Reputation: 4778
I have a jar task that is configured to copy contents of my custom defined zip archive dependencies into a particular sub-folder of the jar archive:
configurations {
docs
javadocs
}
dependencies {
...
docs "mygroup:myartifact:0.0.1-SNAPSHOT:docs@zip"
javadocs "mygroup:myartifact:0.0.1-SNAPSHOT:javadoc"
}
jar {
...
from ( configurations.docs.collect { zipTree(it) } ) {
into 'static/docs'
}
from ( configurations.javadocs.collect { zipTree(it) } ) {
into "static/docs/${name}/${version}/javadoc"
}
}
That works for docs dependencies well. For javadoc, as you can see I need access to the corresponding dependency name and version to copy the content into a specific subfolder of the jar. It would overlap otherwise and I don't control the internal folder structure of the javadocs dependencies.
Is there a way to access/use the Gradle API to achieve the sketched functionality?
Upvotes: 0
Views: 1094
Reputation: 2610
Try this (not fully tested; using Gradle 3.5):
jar {
...
from ( configurations.docs.collect { zipTree(it) } ) {
into 'static/docs'
}
configurations.javadocs.resolvedConfiguration
.firstLevelModuleDependencies.each { ResolvedDependency dep ->
into("static/docs/${dep.moduleName}/${dep.moduleVersion}/javadoc") {
from(dep.moduleArtifacts.collect { zipTree(it.file) })
}
}
}
I hacked it together after poking around the Gradle javadoc for Configuration
here.
Upvotes: 2