How to include all src/test/resources/** AND src/main/java/**/*.html in the test sourceset in gradle?

The following will illustrate the technique using main (so it can be verified):

apply plugin: 'java'

sourceSets {
    myExtra {
        resources {
            srcDirs "src/main/java"
            includes = ["**/*.html"]
        }
    }
    main {
        resources {
            source myExtra.resources
        }
    }
}

Proof of concept via the command-line:

bash$ ls src/main/java
abc.html
xyz.txt

bash$ ls src/main/resources/
def.html
ijk.txt

bash$ gradle clean jar
bash$ jar tf build/libs/myexample.jar
META-INF/
META-INF/MANIFEST.MF
abc.html
def.html
ijk.txt

In your case, change main to test. This answer was discovered via the Gradle doc for SourceDirectorySet. Interestingly, for 3.0, it contains a TODO:

TODO - configure includes/excludes for individual source dirs

which implies that this work-around (via this method) is probably necessary.


I got your point. I tried this and it worked . Please take a look into it:

sourceSets {
    test {
        resources {
            srcDirs = ["src/main/java"]
            includes = ["**/*.html"]
        }
    }
}

sourceSets.test.resources.srcDir 'src/test/resources'

Add these in build.gradle.

Tags:

Gradle