Reputation: 35
Hi I've inherited a project which is very poorly strung together. Its using gradle but still using uploadArchives. Its current artificat definition is something like this
artifacts {
if (someCondition) {
{
archives archive1
}
if (someOtherCondition) {
archives archive2
}
I'd like to switch to ivy/maven publishing, i'm using ivy for now as I have a small bit of experience(minimal) with it on other gradle projects.
This project has a number of problems but I'd like to be able to say have tasks called publishArchive1 or publishArchive2 that a build can call specifically. Maybe I am searching the wrong terms but I cant figure this out.
Upvotes: 1
Views: 1086
Reputation: 35
In a typical turn of events once I decided to post a question I found my answer in a way. Though I perhaps poorly phrased my question I was unaware that for each publication block defined gradle creates a tasks to publish just that one.
For reference this guide described it https://docs.gradle.org/current/userguide/publishing_setup.html#publishing_overview
in particular this excerpt
In combination with the project’s group and version, the publication and repository >definitions provide everything that Gradle needs to publish the project’s production JAR. >Gradle will then create a dedicated publishMyLibraryPublicationToMyRepoRepository task >that does just that. Its name is based on the template >publishPubNamePublicationToRepoNameRepository. See the appropriate publishing plugin’s >documentation for more details on the nature of this task and any other tasks that may be >available to you.
This detail was missing from the gradle ivy publishng plugin documentation I was looking at before.
Upvotes: 1
Reputation: 22952
You are looking for the Maven Publish plugin.
You can create a single publication, then conditionally add artifacts to that publication which should align with what you have provided in the sample.
publishing {
publications {
maven(MavenPublication) {
// Configure other options here
// ...
if (someCondition) {
from(someTaskWithOutputs)
}
if (someCondition) {
from(someOtherTaskWithOutputs)
}
}
}
}
Then just call ./gradlew publish
which will publish to all defined repositories. See the linked guide for more details
Upvotes: 1