Reputation: 753
I have a gradle build that must publish a pre-built jar file as an artifact. By some reason it is not being picked up. Here's a simplified version to reproduce it:
folder contents:
settings.gradle
build.gradle
some.jar
settings.gradle:
rootProject.name = 'some'
build.gradle:
apply plugin: 'base'
apply plugin: 'maven-publish'
group = 'foo.bar'
version = '1.0'
task copyPrebuilt(type: Copy) {
from(projectDir) {
include 'some.jar'
rename 'some', "some-$version"
}
into distsDir
}
artifacts {
// should be 'archives'?
// http://stackoverflow.com/questions/39068090/gradle-archives-artifacts-not-populated-to-default-configuration
'default' (file("$distsDir/some-${version}.jar")) {
name 'some'
type 'jar'
builtBy copyPrebuilt
}
}
some-1.0.jar
is not copied to ~/.m2/repository/foo/bar/some/1.0
by gradle publishToMavenLocal
any clues?
Upvotes: 3
Views: 7221
Reputation: 4908
Personally, I have to declare a builtby
with the artifact like that:
publishing {
publications {
gpr(MavenPublication) {
artifact("build/libs/myjar-version.jar") {
builtBy shadowJar
}
groupId 'com.elikill58'
artifactId 'myjar'
}
}
}
Don't forget to change variable as your own.
Upvotes: 0
Reputation: 11443
The easiest way to get something published is to define a publication object:
apply plugin: 'base'
apply plugin: 'maven-publish'
group = 'foo.bar'
version = '1.0'
task copyPrebuilt(type: Copy) {
from(projectDir) {
include 'some.jar'
rename 'some', "some-$version"
}
into buildDir
}
publishToMavenLocal.dependsOn copyPrebuilt
publishing {
publications {
prebuilt(MavenPublication) {
artifact file("$buildDir/some-${version}.jar")
}
}
}
This code makes publishToMavenLocal
task install some-1.0.jar to the local maven repository.
Upvotes: 5