vanniktech / gradle-maven-publish-plugin

A Gradle plugin that publishes your Android and Kotlin libraries, including sources and javadoc, to Maven Central or any other Nexus instance.
https://vanniktech.github.io/gradle-maven-publish-plugin
Apache License 2.0
1.29k stars 118 forks source link

[Question] How to set artifactId for individual modules #280

Closed ntoskrnl closed 3 years ago

ntoskrnl commented 3 years ago

We set up a base-plugin in our project, and the library has several modules. Pom config is set up via gradle DSL (i.e. using pom { }) as described in README.

When I publish, the plugin uses gradle module name as artifactId and I would like to change it. How do I set up artifactId for each module individually?

I tried adding POM_ARTIFACT_ID = ... or pom.artificatId = ... inside mavenPublishing { } block of the module, but it didn't work.

ntoskrnl commented 3 years ago

I found a solution. For android publications the plugin's configure() method creates a publication named "maven". We can find it by name and change artifactId. But I just applied name to all publications (there will only be one per Gradle module anyway).

I added this to the module:

publishing {
    publications.all { p ->
        p.artifactId = "newname"
    }
}
RBusarow commented 2 years ago

Thank you, @ntoskrnl, for posting your solution! This needs to be translated a little bit in order to work for the Kotlin DSL.

In Kotlin, publications gives us a collection of Publication, which doesn't have the artifactId property. We need to cast that p: Publication to a MavenPublication.

publishing {
  publications
    .filterIsInstance<MavenPublication>()
    .forEach { p ->
      p.artifactId = "my-artifact-id"
    }
}