Last active
August 16, 2016 05:07
-
-
Save childnode/b8ae38d4962e3a77c3a2b233d63cf732 to your computer and use it in GitHub Desktop.
How do I add a new sourceset to Gradle? http://stackoverflow.com/a/37882006/529977
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'java' | |
// apply the runtimeClasspath from "test" sourceSet to the new one | |
// to include any needed assets: test, main, test-dependencies and main-dependencies | |
sourceSets { | |
integrationTest { | |
compileClasspath += sourceSets.test.runtimeClasspath | |
// somehow this redeclaration is needed, but should be irrelevant | |
// since runtimeClasspath always expands compileClasspath | |
runtimeClasspath += sourceSets.test.runtimeClasspath | |
} | |
} | |
// define custom test task for running integration tests | |
task integrationTest(type: Test) { | |
testClassesDir = sourceSets.integrationTest.output.classesDir | |
classpath = sourceSets.integrationTest.runtimeClasspath | |
} | |
integrationTest.dependsOn test |
open for testing and analysis, as found in https://github.com/bmuschko/gradle-docker-plugin/blob/master/gradle/integration-test.gradle
sourceSets {
integrationTest {
java
resources
compileClasspath += sourceSets.main.output + sourceSets.testSetup.output + configurations.testRuntime
runtimeClasspath += output + compileClasspath
}
}
task integrationTest(type: Test) {
description = 'Runs the integration tests.'
group = 'verification'
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
mustRunAfter test
reports {
html.destination = project.file("$html.destination/integration")
junitXml.destination = project.file("$junitXml.destination/integration")
}
}
check.dependsOn integrationTest
idea.module {
sourceSets.integrationTest.allSource.srcDirs.each {
testSourceDirs += it
}
scopes.TEST.plus += [configurations.integrationTestCompile]
scopes.TEST.plus += [configurations.integrationTestRuntime]
}
The latter block reads like "enabling IntelliJ Idea handling integrationTest sourceSet as test module"
see also: https://gist.github.com/childnode/6df6d14c6b3aa47a327bb73ffd731444
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(!) as it turns out, the single use of sourceSet enhancements without configurations or output results in a make error in idea after initally opening a project. the build dependency (here: test) for the new "module" (here: integrationTest) isn't available upon first
compileTestJava