Copy all created & third-party jars into a single folder with Gradle

☆樱花仙子☆ 提交于 2019-12-18 16:33:12

问题


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?


回答1:


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])


来源:https://stackoverflow.com/questions/24868668/copy-all-created-third-party-jars-into-a-single-folder-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!