# How to add resources in the source tree to the .jar file?

(ngalarneau) #1

I have .fxml files intermixed with my groovy files in my source tree.

How can I get the .fxml files included in my project’s .jar file?

I tried adding the groovy.srcDir into the resources.srcDir, but that included everything, including the .groovy files.

Thanks,

Neil

(Peter Niederwieser) #2

Either keep resource files in ‘src/main/resources’, or reconfigure ‘sourceSets.main.resources.srcDirs’ and ‘sourceSets.main.resources.includes’ (or ‘excludes’).

(ngalarneau) #3

I changed my resources declaration to:

srcDirs = ['../src/main/resources', fileTree(dir: '../src/main/groovy').matching { include '**/*.fxml' }]


Now when I run the :framework:assemble target, I get the exception below.

I don’t know how to add the .fxml files in the source tree to the Source Set properly.

Is the Java Plugin doc, section 23.7 (Working with source sets), the best doc available for Source Sets?

Thanks, Neil

(Peter Niederwieser) #4

You’ll want something like:

sourceSets {
main {
resources {
srcDirs = ["src/main/groovy"]
includes = ["**/*.fxml"]
}
}
}


For API details it’s usually best to check the Gradle Build Language Reference.

(ngalarneau) #5

Thank you, I have something similar working:

resources {
srcDirs = ['../src/main/resources', '../src/main/groovy']
include 'com/abinitio/a/b/c/**'
exclude '**/*.groovy'
}


If fileTree worked inside sourceSets this could be more precise, but I guess it doesn’t. The doc doesn’t make it clear where fileTree works & where it doesn’t.

The DSL doc on SourceSet (http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.SourceSet.html) doesn’t explain how it works or what can be included in a SourceSet. Include is not mentioned & although it gives an example of exclude, it doesn’t explain, or better yet, specify its behavior (especially its behavior in combination with other things that can occur in a SourceSet declaration).

I’m still glad the doc is there: it is better than nothing. It is not very useful for beginners, however.