gradle-maven-publish-plugin
gradle-maven-publish-plugin copied to clipboard
Base plugin does not allow configuring artifact ID
I was just trying to migrate my project to use this plugin. But unfortunately, I couldn't find a way to configure the artifactId without going through hoops, and the default project name doesn't really work for my use case.
Ideally, I'd like to be able to just configure an artifactId
field on the MavenPublishBaseExtension
directly, or perhaps, via the Platform API (like AndroidLibrary(..., artifactId = xxx)
for example).
I wonder if there was any technical reason behind this, or if it was just an oversight in the library
This is intentional. The main reason is that there is no direct API for that. Unlike group
and version
, name
is final on Project and that's where the artifact id is coming from by default.
There are 2 ways right now for you to modify it:
- Change the name of the project in
settings.gradle
. Here it is still mutable and this way it doesn't need to match the folder name. The downside is that the name also affects when you reference the project like in a dependencyproject("new-name")
. This is the safest way to do it. - You use Gradle APIs to do it
publishing {
publications.withType(MavenPublication::class.java).configureEach { publication ->
publication.artifactId = 'new-name'
}
}
As you can see this uses all
, so if there would be more than one publication this doesn't work. In regular Android projects there is just one, but that isn't the case with Kotlin Multiplatform or Gradle plugins for example.
The way we're doing it for the main plugin is like 2, but the approach is fairly hacky (you can see the code here. I'll leave this open for now, maybe we can add it as an experimental API
Hi @gabrielittner Thanks for the detailed response. Regarding (1), I felt like project name != artifact ID, so I wasn't completely comfortable with this option. And like you said, (2) as is might do more work than is necessary.
I had imagined that it'll be possible to pass the artifactId
as well at the point of instantiating a platform (especially for those whole publications we create
), which is how I'd done this when manually wiring things together. But I suppose this might make for an inconsistent API for other platforms whose publications aren't created by us.
I ended up with something close to (2), which isn't much better since I'm now depending on the internal publication name
publications.named<MavenPublication>("maven") {
artifactId = "new-name"
}
I forgot to mention that I opened an issue at Gradle a while ago which asks them to add a new that allows to provide the default artifact id https://github.com/gradle/gradle/issues/16967
Since there is no activity on the Gradle side the next release of the plugin will now have a coordinates
method that allows setting group, artifactId and version