Copy all created & third-party jars into a single folder with Gradle
Add this piece of code to root build.gradle and it should work fine:
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
}
task copyJars(type: Copy, dependsOn: subprojects.jar) {
from(subprojects.jar)
into project.file('dest')
}
task copyDeps(type: Copy) {
from(subprojects.configurations.runtime)
into project.file('dest/lib')
}
task copyFiles(dependsOn: [copyJars, copyDeps])
Dominic
Updated on June 04, 2022Comments
-
Dominic almost 2 years
we have a multi-project gradle setup with one Java jar for each subproject:
- root-project |-sub-project-a |-sub-project-b |-sub-project-c
Now, because we are creating a Java webstart application, we need to sign all project jars as well as all third-party libraries (dependencies).
My approach was now to copy all built subproject jars and all third-party libraries into a seperate folder and execute a task for signing them. However I am not able to copy the jars.
This was my approach in the root build.gradle:
task copyFiles(type: Copy, dependsOn: subprojects.jar) { from configurations.runtime from("build/libs") into("webstart/lib") include('*.jar') }
together with:
task signAll(dependsOn: [copyFiles]) << { new File('webstart/signed').mkdirs() def libFiles = files { file('webstart/lib').listFiles() } ... }
Then I tried to execute gradle signAll. However, I can only find an empty jar with the name of the root project in the webstart/lib folder.
Maybe my approach is completely wrong. What do I have to do to copy all created & thrid-party jars into a single folder?