Mixing includes and excludes

(Michael Migdol) #1

I have a legacy project that I’m trying to gradle-ize. Our source directory has test files interspersed throughout. The structure is something like:

com.foo.a.SomeClass com.foo.a.SomeClassTest com.foo.b.SomeOtherClass com.foo.b.SomeOtherClassTest

How do I specify a Java source set to compile only the “main” com.foo.a package?

I tried:

main {
    java {
        include "com/foo/a/**/*.java"
        exclude "**/*Test.java"

but it appears that includes and excludes are mutually exclusive. (This isn’t explicitly stated at http://www.gradle.org/docs/current/javadoc/org/gradle/api/tasks/util/PatternFilterable.html, but it is implied…)

Do I have to result to using an include closure instead ? What would this look like?

(Peter Niederwieser) #2

Your solution looks correct, provided that main classes and test classes share the same source root (‘src/main/java’ by default).