What is the pom { } block on a MavenPublication, and why might you need to populate it before publishing a library?
answer
- generated pom.xml from MavenPublication
- Gradle fills GAV + dependencies only
- name/description/url/licenses/developers/scm
- Maven Central rejects missing metadata
- pom { } configures MavenPom
basics
~10 sThe pom { } block lets you set metadata (name, description, url, licenses, developers, scm) written into the generated pom.xml. You populate it because repositories like Maven Central reject artifacts missing this metadata.
solid answer
~40 sEvery `MavenPublication` produces a `pom.xml`. By default Gradle only fills in the GAV coordinates and dependencies — it does **not** know your project's human-readable name, description, license, authors, or source location. The `pom { }` block on the publication lets you set those: `name`, `description`, `url`, `licenses { license { ... } }`, `developers { developer { ... } }`, and `scm { ... }`. You need it primarily because **Maven Central (Sonatype) validation rejects** POMs that lack a name, description, url, at least one license, a developer, and SCM info. Even for internal repos it's good hygiene so consumers can discover provenance. The block is configured lazily and applies to whichever `MavenPublication` you declare under `publishing { publications { } }`.
code
kotlin · 12 linespublishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
pom {
name.set("My Library")
description.set("A concise summary")
url.set("https://example.com/my-lib")
}
}
}
}go deeper
Know that pom { } sets human-readable metadata and that Central requires it.
Name the specific required fields and that GAV + deps are automatic.
Explain lazy Property configuration and how the POM ties to component variants.
Frame POM completeness as a publishing-governance / supply-chain-provenance concern across many modules.
## What a POM is A **POM** (Project Object Model) is the `pom.xml` metadata file Maven-style repositories use to describe a published artifact: its coordinates, dependencies, and descriptive metadata. When you publish with the `maven-publish` plugin, Gradle **generates** a `pom.xml` from your `MavenPublication`. ## What Gradle fills in automatically Out of the box Gradle populates: - **GAV coordinates** — `groupId` (from `project.group`), `artifactId` (the publication name / archivesName), `version` (from `project.version`). - **dependencies** — derived from the variants/configurations the component exposes (e.g. `api`/`implementation` mapped to `compile`/`runtime` scopes). It does **not** infer human metadata — there is nowhere for Gradle to learn your project's display name, description, license, or source URL. ## The pom { } block Inside a `MavenPublication` you configure a `MavenPom` via the `pom { }` block. Common properties: - `name` — display name - `description` — one-line summary - `url` — project home page - `licenses { license { name; url } }` - `developers { developer { id; name; email } }` - `scm { connection; developerConnection; url }` ```kotlin publishing { publications { create<MavenPublication>("maven") { from(components["java"]) pom { name.set("My Library") description.set("A concise summary") url.set("https://example.com/my-lib") licenses { license { name.set("The Apache License, Version 2.0") url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") }} developers { developer { id.set("jdoe"); name.set("Jane Doe"); email.set("[email protected]") }} scm { connection.set("scm:git:git://github.com/me/my-lib.git") developerConnection.set("scm:git:ssh://github.com/me/my-lib.git") url.set("https://github.com/me/my-lib") } } } } } ``` ## Why it matters **Maven Central** (via Sonatype/Central Portal) enforces a metadata checklist and rejects publications missing name, description, url, a license, a developer, and SCM. So even if your code builds fine, publishing fails validation without a populated `pom { }`. The properties are Gradle `Property<T>` types configured lazily — set them with `.set(...)` in Kotlin DSL or `=` in Groovy.
- Which metadata fields does Maven Central require beyond GAV coordinates?name, description, url, at least one license, at least one developer, and scm (connection/developerConnection/url).
- Does Gradle put dependencies into the POM automatically?Yes — they're derived from the component's variants/configurations, mapped to Maven scopes. You don't write them in the pom { } block.
saying these in an interview costs you the question
- Claiming Gradle auto-generates name/description/license — it doesn't.
- Thinking pom { } is where you list dependencies.