in Code

GRADLE: How to specify resources from different folders on your sourceSet

Sometimes you need to have resources in your sourceset and these may come from different locations on disk, the official documentation is lacking in real world examples, or at least I just didn’t understand it very well, but from reading forums I finally got it to work.

In the example I specify what files to include/exclude from two different folders.
When the final .jar is created, they’ll keep the package path structure that lives inside the given srcDir folders.

If you just want to add these files (for some reason to the root of your resulting jar, you should make srcDir the full path to where the files live)

sourceSets {
main {
java {
//your java source paths and exclusions go here…
}

resources {
srcDir ‘components/resources/src/main/resources’
include ‘**/*.properties’
include ‘**/*.png’
include ‘**/*.gif’
include ‘**/*.jpg’
include ‘**/*.html’
include ‘**/*.js’
include ‘**/*.sh’
include ‘**/*.dat’
include ‘**/*.icc’
exclude ‘**/*.DS_Store’

srcDir ‘common/vuze/azureus2/src’
include ‘**/Messages*.properties’
exclude ‘**/*.class’
exclude ‘**/*.java’
}
}
}

Write a Comment

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.