Gradle自定义测试sourceSet [英] Gradle custom test sourceSet
问题描述
我有一个gradle项目,并以 main 和 test 作为sourceSet.
我确实希望test-main不成为测试源集的一部分.现在我遇到的问题是,在构建项目时,将 test-main 标记为 Sources Root ,而不是 Test Sources Root .>
这会导致编译错误,我必须手动将 test-mains 标记为所有子项目的Source Test Root.
我创建了一个任务来强制intellij将其标记为Sources Test Root,但似乎我做错了事.
提示:
- Intellij IDEA 2016.2
- 2.14级
谢谢
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
}
[...]
}
我必须为此插件指定:
subprojects {
apply plugin: 'idea'
idea {
module {
testSourceDirs += file('test-mains')
}
}
}
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
}
[...]
}
I had to specify for idea plugin this:
subprojects {
apply plugin: 'idea'
idea {
module {
testSourceDirs += file('test-mains')
}
}
}
这篇关于Gradle自定义测试sourceSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!