简体   繁体   English

使用 Kotlin DSL 进行集成测试的单独 Gradle 源集

[英]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.

相关问题 使用 Gradle Kotlin DSL 进行集成测试 - Integration tests with Gradle Kotlin DSL 使用 Kotlin Gradle DSL 向 Kotlin 项目添加集成测试 - Adding integration tests to Kotlin project using the Kotlin Gradle DSL 如何在同一源集中将gradle单元测试与集成测试分开? - How do I separate gradle unit tests from integration tests in the same source set? Gradle(Kotlin DSL)测试未执行 - Gradle (Kotlin DSL) tests not executed 使用 Gradle Kotlin DSL 和 Intellij 的自定义测试源集 - Custom test source set with Gradle Kotlin DSL and Intellij 在带有 micronaut 和 kotlin 的 gradle 项目中,如何分离单元测试和集成测试? - How to separate unit and integration tests when in gradle project with micronaut and kotlin? 如何使用 Gradle Kotlin DSL 运行 kotlintest 测试? - How to run kotlintest tests using the Gradle Kotlin DSL? 如何使用 gradle 项目的集成测试(kotlin DSL)配置 nebula.integtest? - How to configure nebula.integtest with gradle project's integration tests ( kotlin DSL)? 如何使用 Gradle Kotlin DSL 从 gradle 脚本中的单独 .gradle 文件中调用函数? - How can I call a function from a separate .gradle file from a gradle script using the Gradle Kotlin DSL? 将 JOOQ 与 Kotlin Gradle DSL 结合使用 - Using JOOQ with Kotlin Gradle DSL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM