Maven-publish plugin uploading single artifact 4 times


(Adam Kaufman) #1

I am using the maven-publish plugin (gradle 1.10) to manage uploading of a java project’s artifact to a Nexus repository. This works fine, with one caveat – it uploads it 4 times. Here are the relevant parts of my ‘build.gradle’:

ext.generatedSources = "${buildDir}/generated-sources"
sourceSets {
    main {
        java {
            srcDirs generatedSources
        }
    }
}
  task generateWsdlCode {
    // generate some java source to generatedSources using ant.wsimport
}
  task generateSchemaCode {
    // generate some java source to generatedSources using ant.xjc
}
  task generateEnumCode {
    // generate some java source to generatedSources using ant.xslt
}
  compileJava.dependsOn(generateWsdlCode, generateSchemaCode, generateEnumCode)
  publishing {
    publications {
        mycomponentJar(MavenPublication) {
            from components.java
        }
    }
}

This part is applied from another file:

allProjects {
    plugins.withType(MavenPublishPlugin).whenPluginAdded {
        publishing {
            repositories {
                mavenLocal()
                if (publishToNexus) {
                    maven {
                        url nexusURL
                        credentials {
                            username = nexusUser
                            password = nexusPass
                        }
                    }
                }
            }
        }
    }
}

When I run ‘gradle publish’, I end up with 4 uploads to mavenLocal:

:generatePomFileForMavenJavaPublication
:processResources UP-TO-DATE
:generateEnumCode UP-TO-DATE
:generateSchemaCode UP-TO-DATE
:generateWsdlCode UP-TO-DATE
:compileJava UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:publishMavenJavaPublicationToMavenLocal2Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.195851-1.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenLocal3Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.195851-2.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenLocal4Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.195851-3.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenLocalRepository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.195851-4.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publish

When I run ‘gradle publish -PpublishToNexus=true’, I get 4 uploads to each repository, for a total of 8:

:generatePomFileForMavenJavaPublication
:processResources UP-TO-DATE
:generateEnumCode UP-TO-DATE
:generateSchemaCode UP-TO-DATE
:generateWsdlCode UP-TO-DATE
:compileJava UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:publishMavenJavaPublicationToMaven2Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200221-1.jar to repository remote at http://my.nexus.server/content/repositories/snapshots
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMaven3Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200223-2.jar to repository remote at http://my.nexus.server/content/repositories/snapshots
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMaven4Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200223-3.jar to repository remote at http://my.nexus.server/content/repositories/snapshots
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenLocal2Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200224-5.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenLocal3Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200224-6.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenLocal4Repository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200224-7.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenLocalRepository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200224-8.jar to repository remote at file:/home/myuser/.m2/repository/
Transferring 4402K from remote
Uploaded 4402K
:publishMavenJavaPublicationToMavenRepository
Uploading: com/mycompany/mycomponent/SNAPSHOT/mycomponent-20131219.200224-4.jar to repository remote at http://my.nexus.server/content/repositories/snapshots
Transferring 4402K from remote
Uploaded 4402K
:publish

What have I missed?