Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a sourceset for all java sub-projects

I wonder if it is possible to define a source set in gradle (e.g. integrationTests) that can be applied to all sub-projects that use the 'java' plugin?

Something like

sourceSets {
    integTest {
        java.srcDir file('src/integration-test/java')
        resources.srcDir file('src/integration-test/resources')
        compileClasspath = sourceSets.main.output + configurations.integTest
        runtimeClasspath = output + compileClasspath
    }
}

as mentioned here applied to all java sub-projects?

Thanks for useful hints!

like image 644
u6f6o Avatar asked Oct 02 '22 05:10

u6f6o


1 Answers

You can filter the subprojects of your build by applied plugin. In your example this would look like this:

def javaProjects() {
    subprojects.findAll { project -> 
        project.plugins.hasPlugin('java') 
    }
}

configure(javaProjects()) {
    sourceSets {
        integTest {
            java.srcDir file('src/integration-test/java')
            resources.srcDir file('src/integration-test/resources')
            compileClasspath = sourceSets.main.output + configurations.integTest
            runtimeClasspath = output + compileClasspath
        }
    }
}
like image 85
Benjamin Muschko Avatar answered Oct 13 '22 09:10

Benjamin Muschko