Upload artifact to local and remote maven repositories in one run


(Adam Kaufman) #1

I’ve been futzing with this for awhile now, and I’ve finally narrowed down the behavior. I’m building a tarball, and uploading it to maven repositories. Everything works fine, with one exception: I can’t get both repositories to work at once.

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: mavenLocal().url)
            pom.groupId = rootProject.group
            pom.artifactId = project.name
            pom.version = rootProject.version
        }
        if (publishToNexus) {
            mavenDeployer {
                repository(url: nexusURL) {
                    authentication(userName: nexusUser, password: nexusPass)
                }
                pom.groupId = rootProject.group
                pom.artifactId = project.name
                pom.version = rootProject.version
            }
        }
    }
}

The behavior is very simple – the last repository to be configured wins. The configuration above leads to an upload to nexus. If I put the mavenLocal repository block after the nexus one, then it will upload to mavenLocal. Is it possible to do both at once?


(Peter Niederwieser) #2

For publishing to the local Maven repo, you need to configure ‘mavenInstaller’, not ‘mavenDeployer’. After changing that and removing the if-statement, ‘gradle install uploadArchives’ should do the job.


(Adam Kaufman) #3

Hmm, doesn’t quite work. You see, the ‘install’ task appears to be supplied by the java plugin, which I don’t happen to be using for this project. I’m packing python scripts into a tarball with the goal of storing them in nexus for unified distribution along with our various java packages. The only reason for the explicit local repository is to enable local testing without polluting the central repository.

That said, the net effect of all of this is that if the property that disables the ‘publishToNexus’ flag is supplied, the archive is uploaded to the local repository. This achieves the primary goal. It just won’t upload to both at once, which is somewhat of a nice to have for build optimization.