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.



(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

org.gradle.api.GradleException: Could not determine the dependencies of task ‘:framework:processResources’.

at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.resolve(

at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.getDependencies(

at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.addToTaskGraph(

at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.addTasks(

at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure( Caused by: org.gradle.api.UncheckedIOException: Could not normalize path for file ‘C:\path\to\project\framework\directory ‘…\src\main\groovy’’.

at org.gradle.api.internal.file.AbstractFileResolver.normalise(

at org.gradle.api.internal.file.AbstractFileResolver.resolve(

at org.gradle.api.internal.file.AbstractFileResolver.resolve(

at org.gradle.api.internal.file.DefaultSourceDirectorySet.doGetSrcDirTrees(

at org.gradle.api.internal.file.DefaultSourceDirectorySet.getSrcDirTrees(

at org.gradle.api.internal.file.DefaultSourceDirectorySet.resolve(

at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveNested(

at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(

at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileTrees(

at org.gradle.api.internal.file.collections.BuildDependenciesOnlyFileCollectionResolveContext$BuildableFileTreeInternalConverter.convertInto(

(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 ( 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.