Add a gradle sourceset with folders for java, groovy, and resources

3.4k views Asked by At

I have a multi-module project where one of them adds a sourceSet in order to support 3 source folders

apply plugin: 'groovy'
apply plugin: 'java'

configurations {
    componentTestCompile.extendsFrom compile, testCompile
    componentTestRuntime.extendsFrom runtime, testRuntime, componentTestCompile
}

sourceSets {
    componentTest {
        java {
            srcDir 'src/componentTest/java'
        }
        groovy {
            srcDir 'src/componentTest/groovy'
        }
        resources {
            srcDir 'src/componentTest/resources'
        }
        compileClasspath = sourceSets.main.output + configurations.componentTestCompile
        runtimeClasspath = output + compileClasspath + configurations.componentTestRuntime
    }
}


task componentTest(type: Test) {
    testClassesDir = sourceSets.componentTest.output.classesDir
    classpath = sourceSets.componentTest.runtimeClasspath
    reports.html.destination = file("$reports.html.destination/component")
    reports.junitXml.destination = file("$reports.junitXml.destination/component")

    println classpath
}

check.dependsOn componentTest

When executing gradle componentTest the Java code is not compiled (the build directory is not populated with the respective class files). However when applying the above sourceSet to a simple project (single module) it works. I'm a bit lost in figuring out what the problem is here. I have been playing with the expressions

compileClasspath = sourceSets.main.output + configurations.componentTestCompile
runtimeClasspath = output + compileClasspath + configurations.componentTestRuntime

But haven't really been able to get closer to a solution.

0

There are 0 answers