[英]Separate Gradle source set for integration tests using Kotlin DSL
I'm working on a Spring Boot application implemented in Kotlin , and would like to migrate the Gradle build to use the Gradle Kotlin DSL .我正在开发在Kotlin 中实现的 Spring Boot 应用程序,并希望迁移 Gradle 构建以使用Gradle Kotlin DSL 。
The one thing I cannot figure out is how to set up a separate source set and task for my integration tests.我无法弄清楚的一件事是如何为我的集成测试设置单独的源集和任务。
My source tree looks like this:我的源代码树如下所示:
src
├── integrationTest
│ ├── kotlin
│ └── resources
├── main
│ ├── kotlin
│ └── resources
└── test
├── kotlin
└── resources
And the source set and task are set up like this with Gradle's Groovy DSL:使用 Gradle 的 Groovy DSL 设置源集和任务如下:
// build.gradle
sourceSets {
integrationTest {
kotlin {
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
}
}
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
task integrationTest(type: Test, dependsOn: []) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
I've found many examples for using the Gradle Kotlin DSL, and for additional source sets - but nothing for the combination.我找到了许多使用 Gradle Kotlin DSL 和其他源集的示例 - 但没有任何用于组合的示例。
Can anyone help?任何人都可以帮忙吗?
Here's how you can translate the Groovy script to the Kotlin DSL:以下是将 Groovy 脚本转换为 Kotlin DSL 的方法:
java {
sourceSets {
val integrationTest by creating {
kotlin.apply {
compileClasspath += sourceSets["main"].output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
}
}
}
}
configurations["integrationTestCompile"].extendsFrom(configurations["testCompile"])
configurations["integrationTestRuntime"].extendsFrom(configurations["testRuntime"])
val integrationTest by tasks.creating(Test::class) {
val integrationTestSourceSet = java.sourceSets["integrationTest"]
testClassesDirs = integrationTestSourceSet.output.classesDirs
classpath = integrationTestSourceSet.runtimeClasspath
}
Also see: the Migrating build logic from Groovy to Kotlin guide by Gradle另请参阅:Gradle 的Migrating build logic from Groovy to Kotlin指南
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.