[GRADLE-2254] Maven Plugin uploads certain artifacts twice Created: 26/Apr/12  Updated: 04/Jan/13  Resolved: 27/Apr/12

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.1-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Fixed Votes: 0


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 = project.name + '-tests' from sourceSets.test.output }

task testSourcesJar(type: Jar)

{ baseName = project.name + '-tests' classifier = 'sources' from sourceSets.test.allSource }


{ archives sourcesJar, testJar, testSourcesJar }

uploadArchives {
def mvnUser = 'user'
def mvnPassword = 'pwd'

repositories.mavenDeployer {
configuration = configurations.mavenDeployer
uniqueVersion = false

def mainPom = addFilter('main')

{artifact, file -> !artifact.name.endsWith("-tests") }

def testsPom = addFilter('tests')

{artifact, file -> artifact.name.endsWith("-tests") }

def poms = [ mainPom, testsPom ]


{ 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 [1]http://myrepo
Uploading: mygroup/mylib/4.0.0/mylib-4.0.0.jar to repository remote at [2]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 [3]http://myrepo
Transferring 323K from remote
Uploaded 323K
[ant:null] Deploying to [4]http://myrepo
Uploading: mygroup/mylib-tests/4.0.0/mylib-tests-4.0.0.jar to repository remote at [5]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 [6]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 [7]http://myrepo
Transferring 37K from remote
[ant:null] An error has occurred while processing the Maven artifact tasks.
Error deploying artifact 'mygroup:mylib-tests:jar': Error deploying artifact: Failed to transfer file: [8]http://myrepo/mygroup/mylib-tests/4.0.... 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,
[1] http://myrepo
[2] http://myrepo
[3] http://myrepo
[4] http://myrepo
[5] http://myrepo
[6] http://myrepo
[7] http://myrepo
[8] http://myrepo/mygroup/mylib-tests/4.0.0/mylib-tests-4.0.0-sources.jar

Comment by Gradle Forums [ 26/Apr/12 ]

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

Comment by René Gröschke (Inactive) [ 26/Apr/12 ]

The problem here is, that our AbstractMavenResolver reuses one DeployTask in its commitPublishTransaction() method. The problem of reusing a DeployTask is, that the attachedArtifacts cannot be resetted after executing the deploytask.
I have a fix for this issue on my machine, but not yet committed it, since I have not yet created a unit test for this.

Generated at Wed Jun 30 12:16:55 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.