Gradle copy resources, processResources

I am trying to copy 2 folders from a project folder to a jar. When I use the following settings, Gradle copies the files inside the folders, not the folders themselves:

processResources { from 'public' from 'data' } 

I need the folder "projectDir / data" to be copied to "my.jar / data".

+7
gradle
source share
2 answers

The copy specification in Gradle copies the contents of a folder if the specified path in from is a folder.

One solution is to specify the target folder in the jar using the into directive .

 processResources { from 'data' from 'publicFolder' } task data(type: Copy) { from 'data' into 'data' } task publicFolder(type: Copy) { from 'public' into 'public' } 

This will place the contents or source folders in a folder with the same name in the bank. But, as you can see, you will need to repeat the folder names inside the into closure.

Another workaround is to have a parent folder for these resource folders and use that parent folder in the copy specification.

Here you can structure the resource folders:

 <project-folder> | --> res | --> public --> data 

Then in copy spec processResources you can do the following:

 processResources { from 'res' } 

This will create the public and data folders in the last jar file as you want.

+3
source share

There is a 'from' method that accepts a closure with CopySpec.

I would recommend using this instead of breaking down into separate tasks or restructuring your layout.

 processResources { from('data') {into 'data'} from('publicFolder') {into 'publicFolder'} } 
+3
source share

All Articles