[GRADLE-2372] No way to pass source files with extensions other than .groovy and .java to Groovy compiler Created: 05/Jul/12  Updated: 04/Jan/13  Resolved: 11/Jul/12

Status: Resolved
Project: Gradle
Affects Version/s: 1.0
Fix Version/s: 1.1-rc-1

Type: Improvement
Reporter: Gradle Forums Assignee: Peter Niederwieser
Resolution: Fixed Votes: 1


I am trying to tell gradle that files with the `*.dsl` extension should be compiled as groovy files, so I have added a source set with the inclusion pattern and changed the compile task includes property:

sourceSets {
dsl_scripts {

{ include '**/*.dsl' }


compileDsl_scriptsGroovy.includes = ['**/*.dsl']

But when I run the build under a debug mode it skips all `*.dsl` files with the following message:

Skipping task ':compileDsl_scriptsGroovy' as it has no source files

The following line successfully outputs all the files I try to compile:

println sourceSets.dsl_scripts.allSource.matching(

{include '**/*.dsl'}


Also, I found the following snippet in gradle sources:

FileCollection groovyJavaOnly = spec.getSource().filter(new Spec() {
public boolean isSatisfiedBy(File element)

{ return element.getName().endsWith(".groovy") || element.getName().endsWith(".java"); }


spec.setSource(new SimpleFileCollection(groovyJavaOnly.getFiles()));

Is it possible to override? If not, can we add `extensions` property to GroovyCompile?

Comment by Gradle Forums [ 05/Jul/12 ]

Every source directory set has a [1]filter that gets applied after the regular includes/excludes. For the `groovy` source directory set, this filter defaults to including `.java` and `.groovy` files. So instead of adding to `groovy.include`, adding to `groovy.filter.include` should do the job. No other configuration should be necessary.
[1] http://gradle.org/docs/current/javadoc/org/gradle/api/file/SourceDirectorySet.html#getFilter()

Comment by Gradle Forums [ 05/Jul/12 ]

Following your advice I changed the build script to:

sourceSets {

sourceSets.dsl_scripts.groovy.filter.includes = ['**/*.dsl']

{ include '**/*.dsl'}

The message in debug mode disappeared, but the compiler is called as:

14:29:26.690 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingGroovyCompiler] Java compiler arguments: -d /home/myuser/project/build -g -classpath /home/myuser/.gradle/caches/artifacts-13/filestore/org.codehaus.groovy/groovy-all/1.8.6/jar/96a26bfa6e5aea2e3c46df44a19de93a2acd2366/groovy-all-1.8.6.jar:/home/myuser/...cglib-2.2.1-v20090111.jar:/home/myuser/.gradle/caches/artifacts-13/...4cfdf/jsr305-1.3.9.jar

And no dsl files are added to the end of the compilation command. So for some reason the filter is not applied correctly, what do I miss?

Comment by Gradle Forums [ 05/Jul/12 ]

With `includes =`, you are overriding the defaults, and hence you are only including `.dsl` files. What you need is this line:


You don't need to configure the task.

Comment by Gradle Forums [ 05/Jul/12 ]

I removed the configuration for the GroovyCompile task and changed `includes =` to `include(...)`, but the compilation command from NormalizingGroovyCompiler still does not include the `*.dsl` files as last arguments, but

println sourceSets.dsl_scripts.groovy.matching(

{include '**/*.dsl'}


successfully prints all of them.
println sourceSets.dsl_scripts.groovy.filter.includes
[**/*.java, **/*.groovy, **/*.dsl]

Comment by Gradle Forums [ 05/Jul/12 ]

Hmm, seems like a regression introduced by NormalizingGroovyCompiler then. We added another filter there because some people had problems with non-source files being passed to the compiler when they configured their GroovyCompile tasks with sources other than from source sets.

I'll add an issue for this. In the meantime, `compileDsl_scriptsGroovy.groovyOptions.useAnt = true` should solve the problem.

Comment by Gradle Forums [ 05/Jul/12 ]

I get:

15:15:15.351 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:groovyc] /home/myuser/.../dsl_scripts/groovy/.../scripts/include/Included.dsl skipped - don't know how to handle it

Does ant take into account the `org.codehaus.groovy.source.Extensions` file?

Comment by Gradle Forums [ 05/Jul/12 ]

> Does ant take into account the org.codehaus.groovy.source.Extensions file?

Yes it should. There doesn't seem to be a way to configure additional extensions directly on the Ant groovyc task though.

Comment by Vitalii Fedorenko [ 06/Jul/12 ]

What if we add the 'extensions' property to GroovyCompile and make it equal by default to ['java', 'groovy']. Then, instead of 'return element.getName().endsWith(".groovy") || element.getName().endsWith(".java");' in the NormalizingGroovyCompiler.resolveAndFilterSourceFiles we can apply the filter that takes only files which name ends with a string from the 'extensions' list.

Comment by Peter Niederwieser [ 06/Jul/12 ]

Adding a `GroovyCompileOptions.fileExtensions` property sounds sensible. Want to send a pull request?

Comment by Vitalii Fedorenko [ 09/Jul/12 ]


Comment by Peter Niederwieser [ 11/Jul/12 ]

Thanks for the splendid pull request!

Generated at Wed Jun 30 12:20:07 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.