Excluding all subproject jars from the copy task in Gradle

We have a Java webstart application and we want to deploy / copy all third-party libraries to lib / ext / and all our project jar files in lib / after the project was created using Gradle.

Using this answer on a previous question, I was able to almost accomplish this, except that my shared project libraries are copied to both lib / and lib / ext /. However, they should only be copied to lib /.

Now I'm looking for a way to exclude all shared project libraries from this task:

task copyDeps(type: Copy) {
    from(subprojects.configurations.runtime) 
    into project.file('lib/ext')
}

I tried to add something like exclude (subprojects.jar), but I don’t know how I can get all the subproject banks in the parameter that exclude () could pass.

How can i do this? I am also open to other suggestions on how to accomplish the basic task of copying libraries to the above folders.

+4
source share
2 answers

Now I solved my problem by remembering the project jar file names in copyJars, and then excluding them in copyDeps:

List<String> projectLibs = new ArrayList<String>()
task copyJars(type: Copy, dependsOn: subprojects.jar) {    

    eachFile { fileCopyDetails -> 
      projectLibs.add(fileCopyDetails.name)
    }
    from(subprojects.jar) 
    into file('lib')
}

task copyDeps(type: Copy, dependsOn: copyJars) {

    eachFile { fileCopyDetails ->      
      if (fileCopyDetails.name in projectLibs){
        fileCopyDetails.exclude()
      }
    }
    from (subprojects.configurations.runtime)
    into file('lib/ext')
}

If someone has a more pleasant solution, I would be very glad to hear it :-)

+2
source

Here is a shorter solution:

task copyDeps (type: Copy, dependsOn: subprojects.jar) {
    from (subprojects.configurations.runtime) {
        subprojects.jar.each { it.outputs.files.each { exclude it.getName() } }
    }
    into project.file('lib/ext')
}
+2
source

All Articles