Explain the naming pattern of the tasks maven-publish generates for a publication and a repository.
answer
- publish<Pub>PublicationTo<Repo>Repository
- generatePomFileFor<Pub>Publication
- aggregate publish vs publishToMavenLocal
- names derive from declarations
- default repo name = maven
basics
~10 sFor each publication and each repository the plugin generates publish<Pub>PublicationTo<Repo>Repository. It also generates publish<Pub>PublicationToMavenLocal and generatePomFileFor<Pub>Publication, plus aggregate publish and publishToMavenLocal tasks.
solid answer
~40 sThe `maven-publish` plugin generates tasks by **combining the names of declared publications and repositories**. Given a publication `mavenJava` and a remote repository named `myRepo`, you get `publishMavenJavaPublicationToMyRepoRepository`. For the local Maven repo you get `publishMavenJavaPublicationToMavenLocal`. Each publication also gets a `generatePomFileForMavenJavaPublication` task (which the publish tasks depend on). Two **aggregate lifecycle tasks** tie it together: `publish` depends on every `...To<Repo>Repository` task (all remote repos, all publications), and `publishToMavenLocal` depends on every `...ToMavenLocal` task. The names are derived from your `create<MavenPublication>("…")` and `maven { name = "…" }` declarations, so renaming a publication or repository renames the generated tasks — important when wiring CI to publish to one specific target.
code
bash · 6 lines./gradlew tasks --group publishing
# publish
# publishToMavenLocal
# publishMavenJavaPublicationToCorpRepository
# publishMavenJavaPublicationToMavenLocal
# generatePomFileForMavenJavaPublicationgo deeper
Recognize the publish<Pub>PublicationTo<Repo>Repository shape and the two aggregate tasks.
Derive task names from declarations and explain the publication × repository combinatorics.
Use specific generated tasks to scope CI publishing to one target and avoid accidental multi-repo pushes.
Standardize publication/repository naming conventions across modules so generated task names are predictable for shared CI tooling.
## The combinatorial naming rule `maven-publish` generates a task **per (publication × repository) pair**, plus per-publication helpers and two aggregates. The remote-publish pattern is: ``` publish<PublicationName>PublicationTo<RepositoryName>Repository ``` where both names are the **capitalized** versions of what you declared. So: ```kotlin publishing { publications { create<MavenPublication>("mavenJava") { from(components["java"]) } } repositories { maven { name = "corp"; url = uri("https://repo.example.com") } } } ``` yields `publishMavenJavaPublicationToCorpRepository`. ## The full generated set - **`generatePomFileFor<Pub>Publication`** — writes the `pom.xml` into `build/publications/<pub>/`. Useful to inspect the POM without publishing anywhere. - **`publish<Pub>PublicationToMavenLocal`** — installs that publication into `~/.m2/repository`. - **`publish<Pub>PublicationTo<Repo>Repository`** — uploads that publication to that remote repo. - **`publishToMavenLocal`** (aggregate) — depends on all `...ToMavenLocal` tasks. - **`publish`** (aggregate) — depends on **all** `...To<Repo>Repository` tasks (every remote repo). ## Why the names matter Because the names are derived, a CI job that wants to publish to *only one* repo targets the **specific** task (e.g. `publishMavenJavaPublicationToCorpRepository`) rather than the broad `publish`, which would fire **every** repo. Discover the exact names with `./gradlew tasks --group publishing` or `./gradlew tasks --all`. ## Default repository naming If a `maven { }` repository has no explicit `name`, Gradle defaults it to `maven`, producing `...ToMavenRepository`. With multiple unnamed maven repos you must set distinct `name`s, or task names collide.
- If you have two publications and two remote repos, how many publish<Pub>PublicationTo<Repo>Repository tasks exist?Four — one per (publication × repository) pair; the aggregate `publish` depends on all four.
- How do you publish to just one of several configured repositories?Run the specific generated task, e.g. publishMavenJavaPublicationToCorpRepository, instead of the aggregate `publish`, which targets every repo.
- What happens if two maven repos are declared without explicit names?Both default to 'maven', causing a name collision; Gradle requires distinct repository names.
saying these in an interview costs you the question
- Saying `publish` only pushes to one repo — it fans out to every declared remote repository.
- Assuming task names are fixed strings rather than derived from publication/repository names.