How to publish JAR with test fixtures in Gradle?

(Val) #1

The right way to do this would be to use classifier “tests”, but Gradle ignores classifiers:
So, I specified JAR name explicitly:

// Create JAR with test fixtures
task testJar(type: Jar, dependsOn: testClasses) {
    baseName = "${project.archivesBaseName}-tests"
    from sourceSets.test.output

artifacts {
    archives testJar

tasks.uploadArchives.dependsOn testJar

Problem: Gradle is trying to publish mymodule-tests.jar using the same name as the main JAR:

A POM cannot have multiple artifacts with the same type and classifier. Already have MavenArtifact mymodule:jar:jar:null, trying to add MavenArtifact mymodule:jar:jar:null.

(Schalk Cronjé) #2

Have you tried the following?

task testJar(type: Jar, dependsOn: testClasses) {
   classifier = 'tests'
    from sourceSets.test.output

(Val) #3

Yes. Gradle ignores classifiers:

(Schalk Cronjé) #4

That’s a WTF moment for me as I am using classifiers to create source and javadoc jars which are published to Bintray which are then published. This had me confiused until I realised the issue is not the creation of the JAR, but the actual listing inside the POM.

It looks like a bug to me indeed.

(Ezra Epstein) #5

Was this ever resolved. The owner of the Gradle issue closed it this February with a “WONT FIX” but I don’t see a good work-around for publishing multiple artifacts from a build. Is there one?