I’m having some problems getting a gradle build to work as I want it to. I am gradle noob, so I may be approaching this wrongly (though I have looked hard at the docs/forum/stack overflow).
I have a single Java project that contains a bunch of interdependent source and that needs to be packaged in several independent jar files where each jar is an OSGI bundle (the packaging into bundles is for OSGI purposes).
We are using the bnd gradle plugin (biz.aQute.bnd.builder) to prepare the manifest and build the jar files.
For each package we want to produce I have added a task of type Bundle (aQute.bnd.gradle.Bundle). Within that task I have specified:
- A custom name for the resulting jar
- An include to identify the classes to add
- Manifest attributes
For example:
task bundle_lib(dependsOn: ['classes'], type: Bundle) {
from sourceSets.main.output
baseName = baseName + '.' + 'lib'
include([
'src/pattern/to/include'
//...
])
manifest {
attributes(
'Bundle-Version': project.version
//...
)
}
}
So that these bundle tasks are hooked into the build appropriately in relation to the other default tasks (e.g. assemble) I have made each of these bundle tasks dependencies of the default java task. I also removed the actions of that default task (as we are generating the jar in the bundle tasks). So my build.gradle has this in relation to the jar task:
jar {
dependsOn(['bundle_lib'])
deleteAllActions()
}
This is working largely as required. But now I want to publish the generated jar files to a Maven repo and I can’t get this to work.
Whilst the publication step is working, the current problem I have is that, however I add my artifact to the MavenPublication block, the custom name I have used for the bundle jar is ignored and the default is used (it uses the default baseName i.e. the root project name, rather than the name I have used).
publishing {
publications {
mavenJava(MavenPublication) {
// all of these have the same result
//artifact bundle_lib
//artifact bundle_lib.archivePath
//artifact 'path/to/core-0.0.1.jar'
//artifact file ('path/to/core-0.0.1.jar')
}
}
...
}
How can I publish the correctly named artifact to Maven?