Maven publish plugin publishes all artifacts to MavenLocal, but only the last one ends up in Maven repository (Artifactory)

I have a project that uses the maven-publish plugin.

“gradle tasks” correctly shows several publications:

Publishing tasks ---------------- generatePomFileForJavadocPublication - Generates the Maven POM file for publication ‘javadoc’. generatePomFileForMainPublication - Generates the Maven POM file for publication ‘main’. generatePomFileForSchemaPublication - Generates the Maven POM file for publication ‘schema’. publish - Publishes all publications produced by this project. publishJavadocPublicationToMavenLocal - Publishes Maven publication ‘javadoc’ to the local Maven repository. publishJavadocPublicationToMavenRepository - Publishes Maven publication ‘javadoc’ to Maven repository ‘maven’. publishMainPublicationToMavenLocal - Publishes Maven publication ‘main’ to the local Maven repository. publishMainPublicationToMavenRepository - Publishes Maven publication ‘main’ to Maven repository ‘maven’. publishSchemaPublicationToMavenLocal - Publishes Maven publication ‘schema’ to the local Maven repository. publishSchemaPublicationToMavenRepository - Publishes Maven publication ‘schema’ to Maven repository ‘maven’. publishToMavenLocal - Publishes all Maven publications produced by this project to the local Maven cache.

When I run "publishToMavenLocal " I get my main jar, a jar with ‘javadoc’ classifier, and a zip with ‘schema’ classifer in my maven cache.

When I run “publish”, only the zip with the ‘schema’ classifier is left in the “remote” maven repo! I.e. just the “last” publication". The maven repo in question is our corporate Artifactory server.

I see “Uploading: …” printed for all relevant files (pom, and three archives), but only the pom and the final upload are present when I browse the Artifactory repo. I don’t have this problem when publishing to the same repo using Maven.

Ideas?

I should mention that I am publishing a -SNAPSHOT version in case that is relevant.

I noticed something intersting… to do with the unique names that are used for SNAPSHOT versions. As I have observed in the past, the last -# after the timestamp is incremented with each snapshot published.

So your repo would have

Artifact-1.2.3-20130824.031318-1.pom Artifact-1.2.3-20130824.031318-1.jar Artifact-1.2.3-20130824.031318-1.javadoc.jar Artifact-1.2.3-20130824.031318-1-source.jar

and then after the next publish I should have something like: Artifact-1.2.3-20130824.052304-2.pom Artifact-1.2.3-20130824.052304-2.jar Artifact-1.2.3-20130824.052304-2.javadoc.jar Artifact-1.2.3-20130824.052304-2-source.jar

but in this case that last number is incremented after each file is transferred, as shown in the Gradle output “Uploading:” logs

Uploading: some/group/id/Project/1.2.1-SNAPSHOT/Project-1.2.1-20130824.031318-1.pom to repository remote at http://my-maven-repo/libs-snapshot-local/ Transferring 0K from remote Uploaded 0K Uploading: some/group/id/Projectl/1.2.1-SNAPSHOT/Project-1.2.1-20130824.031318-1-javadoc.jar to repository remote at http://my-maven-repo/libs-snapshot-local/ Transferring 281K from remote Uploaded 281K … Uploading: some/group/id/Project/1.2.1-SNAPSHOT/Project-1.2.1-20130824.031319-2.jar to repository remote at http://my-maven-repo/libs-snapshot-local/ Transferring 101K from remote Uploaded 101K … Uploading: some/group/id/Project/1.2.1-SNAPSHOT/Project-1.2.1-20130824.031320-3.pom to repository remote at http://my-maven-repo/libs-snapshot-local/ Transferring 0K from remote Uploaded 0K Uploading: some/group/id/Project/1.2.1-SNAPSHOT/Project-1.2.1-20130824.031320-3-schema.zip to repository remote at http://my-maven-repo/libs-snapshot-local/ Transferring 2K from remote

This looks like a Gradle bug to me, but it may not be what is causing the other files to be missing.

I tried switching to the older ‘maven’ plugin and noticed that my javadoc jar was not included in the upload.

It seems that if I have another archive with a ‘jar’ extension it won’t be considered for upload, even though it has it’s own classifier.

I confirmed this by changing my javadocs from a Jar task to a Zip task and then they appeared, but when I set the extension for the zip task to ‘jar’ they were gone again. In fact you can see that the task that generates the archive is exclued because it shows up in “gradle tasks” when it isn’t considered for the upload.

This seems wrong to me.

Why do I have to fight so much to get something published with multiple classifiers???

After fiddling with the extension of my javadoc archive I tried maven-publish again…

Note that the ‘maven-publish’ plugin is clearly publishing three separate times, with a different artifact each time. Even when I publish to mavenLocal I can see this. I can wipe out my maven cache and do a single publish of the project and the result is this:

ls -l -1 C:\Users\scott.m2\repository\my\group\id\MyProject\1.2.1-SNAPSHOT

total 464

-rw-rw-rw- 1 scott 0 287681 2013-08-25 14:53 MyProject-1.2.1-20130825.185347-1-javadoc.zip

-rw-rw-rw- 1 scott 0

32 2013-08-25 14:53 MyProject-1.2.1-20130825.185347-1-javadoc.zip.md5

-rw-rw-rw- 1 scott 0

40 2013-08-25 14:53 MyProject-1.2.1-20130825.185347-1-javadoc.zip.sha1

-rw-rw-rw- 1 scott 0

456 2013-08-25 14:53 MyProject-1.2.1-20130825.185347-1.pom

-rw-rw-rw- 1 scott 0

32 2013-08-25 14:53 MyProject-1.2.1-20130825.185347-1.pom.md5

-rw-rw-rw- 1 scott 0

40 2013-08-25 14:53 MyProject-1.2.1-20130825.185347-1.pom.sha1

-rw-rw-rw- 1 scott 0 103116 2013-08-25 14:53 MyProject-1.2.1-20130825.185348-2.jar

-rw-rw-rw- 1 scott 0

32 2013-08-25 14:53 MyProject-1.2.1-20130825.185348-2.jar.md5

-rw-rw-rw- 1 scott 0

40 2013-08-25 14:53 MyProject-1.2.1-20130825.185348-2.jar.sha1

-rw-rw-rw- 1 scott 0

426 2013-08-25 14:53 MyProject-1.2.1-20130825.185348-2.pom

-rw-rw-rw- 1 scott 0

32 2013-08-25 14:53 MyProject-1.2.1-20130825.185348-2.pom.md5

-rw-rw-rw- 1 scott 0

40 2013-08-25 14:53 MyProject-1.2.1-20130825.185348-2.pom.sha1

-rw-rw-rw- 1 scott 0

2200 2013-08-25 14:53 MyProject-1.2.1-20130825.185349-3-schema.zip

-rw-rw-rw- 1 scott 0

32 2013-08-25 14:53 MyProject-1.2.1-20130825.185349-3-schema.zip.md5

-rw-rw-rw- 1 scott 0

40 2013-08-25 14:53 MyProject-1.2.1-20130825.185349-3-schema.zip.sha1

-rw-rw-rw- 1 scott 0

456 2013-08-25 14:53 MyProject-1.2.1-20130825.185349-3.pom

-rw-rw-rw- 1 scott 0

32 2013-08-25 14:53 MyProject-1.2.1-20130825.185349-3.pom.md5

-rw-rw-rw- 1 scott 0

40 2013-08-25 14:53 MyProject-1.2.1-20130825.185349-3.pom.sha1

-rw-rw-rw- 1 scott 0

372 2013-08-25 14:53 maven-metadata.xml

-rw-rw-rw- 1 scott 0

32 2013-08-25 14:53 maven-metadata.xml.md5

-rw-rw-rw- 1 scott 0

40 2013-08-25 14:53 maven-metadata.xml.sha1

Solved it…

I had been using three different publications instead of multiple archives in a single publication.