【发布时间】:2018-07-21 11:44:59
【问题描述】:
我正在尝试将另一个模块添加到我的 Kotlin 项目中,专门用于集成测试 - 与由 kotlin 插件创建的标准 test 模块一起使用。这是我当前添加sourceset的配置:
sourceSets {
testIntegration {
java.srcDir 'src/testIntegration/java'
kotlin.srcDir 'src/testIntegration/kotlin'
resources.srcDir 'src/testIntegration/resources'
compileClasspath += main.output
runtimeClasspath += main.output
}
}
configurations {
provided
testCompile.extendsFrom provided
testIntegrationCompile.extendsFrom testCompile
testIntegrationRuntime.extendsFrom testRuntime
}
task testIntegration(type: Test) {
testClassesDirs = sourceSets.testIntegration.output.classesDirs
classpath = sourceSets.testIntegration.runtimeClasspath
}
这似乎可行,但是 IntelliJ 不会将新的源集作为测试模块。我可以手动标记它,但每次 Gradle 运行时它都会重置。这也意味着 Intellij 在项目结构设置中填写 Output Path 而不是 Test Output Path 字段。
修复以下配置有效:
apply plugin: 'idea'
idea {
module {
testSourceDirs += project.sourceSets.testIntegration.java.srcDirs
testSourceDirs += project.sourceSets.testIntegration.kotlin.srcDirs
testSourceDirs += project.sourceSets.testIntegration.resources.srcDirs
}
}
但是,这似乎告诉 IntelliJ Test Output Path 是 \out\test\classes,这与标准的“测试”模块相同,并导致冲突问题。我希望它将输出路径保持为原始的\out\testIntegration\classes,否则会被使用。
有什么方法可以指示 IntelliJ 正确选取这个新的测试源集并填写正确的输出路径?
【问题讨论】:
标签: gradle intellij-idea kotlin gradle-plugin intellij-idea-2018