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

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

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

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(CachingTaskDependencyResolveContext.java:65)

at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.getDependencies(CachingTaskDependencyResolveContext.java:53)

at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.addToTaskGraph(DefaultTaskExecutionPlan.java:99)

at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.addTasks(DefaultTaskGraphExecuter.java:74)

at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:49) 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(AbstractFileResolver.java:138)

at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:79)

at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:60)

at org.gradle.api.internal.file.DefaultSourceDirectorySet.doGetSrcDirTrees(DefaultSourceDirectorySet.java:143)

at org.gradle.api.internal.file.DefaultSourceDirectorySet.getSrcDirTrees(DefaultSourceDirectorySet.java:128)

at org.gradle.api.internal.file.DefaultSourceDirectorySet.resolve(DefaultSourceDirectorySet.java:155)

at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveNested(DefaultFileCollectionResolveContext.java:143)

at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:101)

at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileTrees(DefaultFileCollectionResolveContext.java:75)

at org.gradle.api.internal.file.collections.BuildDependenciesOnlyFileCollectionResolveContext$BuildableFileTreeInternalConverter.convertInto(BuildDependenciesOnlyFileCollectionResolveContext.java:50)

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.

1 Like

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.

1 Like