Maven Plugin uploads certain artifacts twice

Hi There,

I’m observing a werid behavior in the Maven Plugin. It seems as if it’s uploading certain artifacts multiple times. So either I’m doing something wrong (which might very well be ;)) or this might be a bug.

I have a basic jar project, of which I want to deploy 4 artifacts: - The main library jar - The sources of the main library jar - A jar containing thecompiled test classes - The sources of the test classes

I want the sources jars to just use classifiers. The test jars should get their own artifactIds.

Here are the relevant parts of my build.gradle:

task sourcesJar(type: Jar) {
     from sourceSets.main.allSource
    classifier = 'sources'
   task testJar(type: Jar) {
    baseName = + '-tests'
    from sourceSets.test.output
  task testSourcesJar(type: Jar) {
    baseName = + '-tests'
    classifier = 'sources'
    from sourceSets.test.allSource
  artifacts {
    archives sourcesJar, testJar, testSourcesJar
  uploadArchives {
    def mvnUser = 'user'
    def mvnPassword = 'pwd'
      repositories.mavenDeployer {
        configuration = configurations.mavenDeployer
        uniqueVersion = false
          def mainPom = addFilter('main') {artifact, file ->
        def testsPom = addFilter('tests') {artifact, file ->
          def poms = [ mainPom, testsPom ]
          poms.each { it.version = project.version }
          repository(url: "http://myrepo") {
            authentication(userName: "${mvnUser}", password: "${mvnPassword}")
        snapshotRepository(url: "http://myrepo-snapshots") {
            authentication(userName: "${mvnUser}", password: "${mvnPassword}")

When I run uploadArchives with --info, I get the following output:

:mylib:uploadArchives Task ‘:mylib:uploadArchives’ has not declared any outputs, assuming that it is out-of-date. Publishing configuration: configuration ‘:mylib:archives’ Publishing to Resolver org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer@29856f5d [ant:null] Deploying to http://myrepo Uploading: mygroup/mylib/4.0.0/mylib-4.0.0.jar to repository remote at http://myrepo Transferring 437K from remote Uploaded 437K [INFO] Retrieving previous metadata from remote [INFO] Uploading repository metadata for: ‘artifact mygroup:mylib’ [INFO] Uploading project information for mylib 4.0.0 Uploading: mygroup/mylib/4.0.0/mylib-4.0.0-sources.jar to repository remote at http://myrepo Transferring 323K from remote Uploaded 323K [ant:null] Deploying to http://myrepo Uploading: mygroup/mylib-tests/4.0.0/mylib-tests-4.0.0.jar to repository remote at http://myrepo Transferring 50K from remote Uploaded 50K [INFO] Retrieving previous metadata from remote [INFO] repository metadata for: ‘artifact mygroup:mylib-tests’ could not be found on repository: remote, so will be created [INFO] Uploading repository metadata for: ‘artifact mygroup:mylib-tests’ [INFO] Uploading project information for mylib-tests 4.0.0 Uploading: mygroup/mylib-tests/4.0.0/mylib-tests-4.0.0-sources.jar to repository remote at http://myrepo Transferring 323K from remote Uploaded 323K Uploading: mygroup/mylib-tests/4.0.0/mylib-tests-4.0.0-sources.jar to repository remote at http://myrepo Transferring 37K from remote [ant:null] An error has occurred while processing the Maven artifact tasks.

Diagnosis: Error deploying artifact ‘mygroup:mylib-tests:jar’: Error deploying artifact: Failed to transfer file: http://myrepo/mygroup/mylib-tests/4.0.0/mylib-tests-4.0.0-sources.jar. Return code is: 400

The HTTP 400 is our repo’s way of indicating the artifact alreacy exists and cannot be overwritten in a release repository. This behavior seems corrent as it looks like gradle is trying to upload the same artifact (mylib-tests-4.0.0-sources.jar) twice.

I have added this code to get the list of artifacts:

configurations.archives.artifacts.each { println "ARTIFACT: ${it}" }

And I got the output:

ARTIFACT: ArchivePublishArtifact mylib:jar:jar:
ARTIFACT: ArchivePublishArtifact_Decorated mylib:jar:jar:sources
ARTIFACT: ArchivePublishArtifact_Decorated mylib-tests:jar:jar:
ARTIFACT: ArchivePublishArtifact_Decorated mylib-tests:jar:jar:sources

Which looks correct to me…

Any clue what might be wrong here?

Many thanks in advance, Mike

Hello Mike, I think you didn’t do anything wrong here and I can reproduce this bug on my machine. Thanks for reporting.

You can track the related jira issue here: GRADLE-2254

Allright, thank you rene :slight_smile: