How to configure the test sourceSet when each package has its own test package?

How to configure the test sourceSet when each package has its own test package ?

My project is organized with a file tree like this : src ------package1 ----------impl ----------tests ------package2 ----------impl ----------tests

I did not manage to set properly the test source set. Do you have any idea to do that ?

Then, the idea would be to export the test jar with the following lines: task testJar(type: Jar) {

classifier = ‘tests’

from sourceSets.test.classes }

Regards, Nicolas

Try something like this:

sourceSets {
    main {
        java {
            srcDirs = ["src"]
            include "**/impl/"
        }
    }
    test {
        java {
            srcDirs = ["src"]
            include "**/tests/"
        }
    }
}

Thank you, the source set seems to be correct; but if i generate the test source jar, there are empty packages inside (as the impl ones). Is there a way that the test source jar contains only the “test” directories ?

I use the following code to generate the jar : task testJar(type: Jar) {

classifier = ‘tests’

from sourceSets.test.allSource }

in order to obtain

package1 ----tests -------Test1.java package2 -------Test1.java

I try to use the include keyword but can not find the correct filter, maybe the wrong way to what i aim ?

The Jar task has an “includeEmptyDirs” property, which you can set to false.

I did not notice that. That’s great !! Thank you very much.