Gradle new maven-publish plugin:
For multiple jars with different classifiers, e.g.,
source sets
src/foo/java
src/bar/java
dependencies {
fooCompile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
barCompile sourceSets.foo.output
}
Jars to build:
productName-1.0-foo.jar
productName-1.0-bar.jar
bar.jar has compile dependency on foo jar.
Gradle:
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'com.example'
artifactId 'productName'
version '1.0'
artifact fooJar {
classifier 'foo'
}
artifact barJar {
classifier 'bar'
}
}
}
publishing {
repositories {
maven {
url "$buildDir/repo"
}
}
}
}
The published repository:
build/repo/com/example/productName/1.0/productName-1.0-foo.jar
build/repo/com/example/productName/1.0/productName-1.0-bar.jar
build/repo/com/example/productName/1.0/productName-1.0.pom
Only one pom without any dependency.
Now separate these with different artifactId (s)
publishing {
publications {
foo(MavenPublication) {
groupId 'com.example'
artifactId 'productName-foo'
version '1.0'
artifact fooJar {
}
}
bar(MavenPublication) {
groupId 'com.example'
artifactId 'productName-bar'
version '1.0'
artifact barJar {
}
}
}
publishing {
repositories {
maven {
url "$buildDir/repo"
}
}
}
}
Each jar gets its own POM:
build/repo/com/example/productName-foo/1.0/productName-foo-1.0.jar
build/repo/com/example/productName-foo/1.0/productName-foo-1.0.pom
build/repo/com/example/productName-bar/1.0/productName-bar-1.0.jar
build/repo/com/example/productName-bar/1.0/productName-bar-1.0.pom
Two issues:
- the classifier (foo, bar) is not after version in jar name.
- the generated POM.xml files for foo and bar do not have dependency.