Reputation: 5542
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:
Upvotes: 4
Views: 5701
Reputation: 11
Here is an alternative approach that works for me. Something similar might work for you:
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
// If needed the javadoc task can be commented, comment javadoc from artifacts and publish as well.
task javadocJar(type: Jar, dependsOn: javadoc){
classifier = 'javadoc'
from javadoc.destinationDir
}
task testJar(type: Jar, dependsOn: testClasses) {
from sourceSets.test.output
appendix 'test'
}
artifacts{
archives sourcesJar
archives javadocJar
archives testJar
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
}
mavenTest(MavenPublication) {
artifactId project.name + "-test"
artifact testJar {
appendix 'test'
}
}
}
}
artifactory {
publish {
defaults {
publications ('mavenJava', 'mavenTest')
}
}
}
Upvotes: 0