shadow: uploadX task fails if both shadow 2.0.x and application plugin are applied.

Shadow Version

1.2.4 vs. 2.0.0/2.0.1

Gradle Version

4.3.1/4.4-rc1

Expected Behavior

This example project (build.gradle is also provided below) should work with 2.0.x since it worked with 1.2.4. Execute gradlew to run the default tasks.

Actual Behavior

Execution failed for task ':uploadPublished'.
> Could not publish configuration 'published'
   > A POM cannot have multiple artifacts with the same type and classifier. Already have MavenArtifact gradle-shadow2:zip:zip:null, trying to add MavenArtifact gradle-shadow2:zip:zip:null.

If you remove the following two lines, the build will work.

apply plugin: 'application'
mainClassName = 'foo.Main'

If you instead switch back from 2.0.1 to 1.2.4, the build will work. If you use Gradle 4.4-rc1, neither will work. See https://github.com/gradle/gradle/issues/3589

Gradle Build Script(s)

buildscript {
    repositories {
    	jcenter()
    }

    dependencies {
        //classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
    }
}

wrapper {
    gradleVersion = '4.3.1'
    // gradleVersion = '4.4-rc1'
}

description = 'some description'
version = '1.0.0-SNAPSHOT'

def localReleaseRepoFile = new File("${System.properties.'user.home'}/local-gradle-repository/release")
def localSnapshotRepoFile = new File("${System.properties.'user.home'}/local-gradle-repository/snapshot")
def localReleaseRepo = localReleaseRepoFile.toURL().toString()
def localSnapshotRepo = localSnapshotRepoFile.toURL().toString()
repositories {
	maven {
		url localReleaseRepo
	}
	maven {
		url localSnapshotRepo
	}
	mavenCentral()
	mavenLocal()
}

apply plugin: 'application'
mainClassName = 'foo.Main'

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.github.johnrengelman.shadow'


def deployer = null

configurations {
	published.extendsFrom archives
}

uploadPublished {
	deployer = repositories.mavenDeployer {
		repository(url: localReleaseRepo)
		snapshotRepository(url: localSnapshotRepo)
	}
}

def defaultProject= {
	url 'http://foobar.com'
	name project.name
	description project.description
}


def installer = install.repositories.mavenInstaller

installer.pom.project defaultProject

deployer.pom.project defaultProject

defaultTasks 'build', 'shadowJar', 'uploadPublished'

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

n/a, content of the JAR is not the problem.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 6
  • Comments: 16

Commits related to this issue

Most upvoted comments

Thanks a lot for your effort. Your suggested workaround works. Just tried it. 👍

Ok, I believe I see what’s happening. According to https://docs.gradle.org/current/userguide/distribution_plugin.html#sec:publishing_distributions_upload ALL distributions are automatically added to the default archive configuration. This means that the outputs from shadowDistZip and shadowDistTar are automatically added to archives and since we don’t do any special configuration of those tasks, they have the default classifier which is null.

You can work around this in your build by adding the following:

shadowDistZip.classifier = 'shadow'
shadowDistTar.classifier = 'shadow'