I have a gradle project and have main and test as sourceSets.
I do want test-main not to be part of test source sets. Now the issue I encounter is that when projects are build, the test-main is marked as Sources Root instead of Test Sources Root.
This leads to compilation errors and I have to manually mark test-mains as Source Test Root for all subprojects.
I created a task in order to enforce intellij to mark them as Sources Test Root but seems like I am doing something wrong.
hints:
- Intellij IDEA 2016.2
- Gradle 2.14
Thanks,
subprojects {
apply plugin: 'java' // all our projects are Java projects
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.warnings = false // There are too many :-(
}
configurations {
testMainsCompile.extendsFrom testCompile
testMainsRuntime.extendsFrom testMainsCompile
}
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
}
}
test {
java {
srcDirs = ['test']
}
resources {
srcDirs = ['test']
}
}
testMains {
java {
srcDirs = ['test-mains']
compileClasspath = test.output + main.output + configurations.testMainsCompile
runtimeClasspath = output + compileClasspath + configurations.testMainsRuntime
}
resources {
srcDirs = ['test-mains']
}
}
}
// dummy task just to convince intellij idea that testMains is a test class folder
task testMainsTest(type: Test) {
testClassesDir = sourceSets.testMains.output.classesDir
classpath += sourceSets.testMains.runtimeClasspath
}
[...]
}