Maven-publish destination repo(snapshot, release) from another task


(Bill Pfeiffer) #1

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).


(DishaRathodCE) #2

Hi,

What I need:

When creating a release, I need the artifact uploaded to nexus repo.

What I do:

I use createReleaseTag.dependsOn uploadArchives.

The problem I have:

If the version is set to 1.0.0-SNAPSHOT, when I start the release, it will ask if it should use version 1.0.0, I will confirm it and the release is performed and tag is created with 1.0.0 version set. However, when I check the nexus repo, the deployed files have version 1.0.0-SNAPSHOT (and are also deployed to the snapshot repo instead of the release repo).

I have tested with net.researchgate:gradle-release:2.0.2 on a windows machine with git. Has anyone else had the same problem?

Thanks in advance, Best Regards,
DevOps Online Training institute in india