I would like to add 2 tasks into my build, one which publishes to a snapshot repo and another that publishes to release. We don’t use versions like most shops (that check for a version ending in “SNAPSHOT”), but rather allow our devops to choose what goes into our release and snapshot artifactory repos. My initial idea is to create a simple task that sets a property that will be the repo URL for the given task name. publishArtSnapshot, publishArtRelease are my two tasks. I simply set the relevent URL property in each task that publishing.maven.url config property is set to:
ext {
myMavenUrl = mavenSnapshotRepo
}
task publishArtSnapshot()
{
myMavenUrl = mavenSnapshotRepo
}
task publishArtRelease()
{
myMavenUrl = mavenReleaseRepo
}
publishing {
repositories {
maven {
url "$myMavenUrl"
credentials {
username "$mavenUsername"
password "$mavenPassword"
}
}
}
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
}
I have seen requests for Snapshot, Release semantics in the maven-publish plugin, but until then would like a means to control publish destination with a task. What would be the proper means to invoke the maven-publish “publishMavenJavaPublicationToMavenRepository” task from one of my two tasks that set the destination URL value?
I have solved this by setting a property from the gradlew invocation and keying off that, but my preference would be to provide the two tasks visible from the available tooling (ide and otherwise).