I’m using Gradle 1.6. For the following project:
apply plugin: 'groovy'
sourceSets {
main {
resources {
source java
exclude '**/*.xml'
}
}
}
with the following files:
$ find src -type f
src/main/java/java.java
src/main/java/java.xml
src/main/java/java.txt
src/main/resources/resource.txt
src/main/resources/resource.xml
src/main/resources/resource.java
calling './gradlew clean processResources does not exclude *.xml files form src/main/java:
$ ./gradlew clean processResources
:clean
:processResources
BUILD SUCCESSFUL
Total time: 3.102 secs
$ find build -type f | sort
build/resources/main/java.txt
build/resources/main/java.xml
build/resources/main/resource.java
build/resources/main/resource.txt
I would expect the java.xml file not to be copied over. Is this supposed to work this way?
wujek
It should be:
apply plugin: 'groovy'
sourceSets {
main {
resources {
srcDirs java.srcDirs
exclude '**/*.xml'
}
}
}
Using the source method means that the other source directory set should be included wholesale (i.e. includes/excludes don’t apply).
No, I had tried that before, there is even a post by me asking somewhere in this forum. What I get is:
$ g clean processResources
Converting class java.util.LinkedHashSet to File using toString() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use java.io.File, java.lang.String, java.net.URL, or java.net.URI instead.
:clean
:processResources
BUILD SUCCESSFUL
Total time: 6.801 secs
$ find -type f build/resources/
build/resources/main/resource.txt
build/resources/main/resource.java
Which means that src/java is not included in resources. If you want it this way, you actually need to do it like this:
srcDirs java.srcDirs as File[]
or
srcDirs = srcDirs + java.srcDirs
I don’t like the looks of the former, and I’ve just came up with the latter ;d That’s why I went on to search deeper and found ‘source’. I guess I will have to live with one of the two. I do understand the reasoning behind ‘source’ being wholesale, it was just surprising at first, and it should probably be documented that such ‘sourcing’ is not affected by further configuration.
wujek
The code I posted should work, it’s a bug that it doesn’t.
I’ve raised GRADLE-2798.
Ok thanks. You might also be interested in this: http://forums.gradle.org/gradle/topics/non_source_files_form_src_main_java_as_resources_and_filtering (that’s the other thread I mentioned, it contains some initial analysis that I made about why the code you posted above doesn’t work).