The right way to do this would be to use classifier “tests”, but Gradle ignores classifiers: https://issues.gradle.org/browse/GRADLE-2381.
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.