Gradle Groovy don'中的测试类;在Kotlin中看不到测试类
我有一个带有Kotlin插件的gradle项目 在我的项目中,我使用groovy和Spock进行测试。 测试中使用的一个实用程序类是用Kotlin编写的,我将它放在src/test/Kotlin中 我试图使用groovy测试中的这个类(Spock规范),我看到“compileTestKotlin”任务首先运行并编译我的实用程序类,但“compileTestGroovy”仍然失败,因为它没有看到它 我怎样才能解决这个问题?Gradle Groovy don'中的测试类;在Kotlin中看不到测试类,gradle,groovy,kotlin,Gradle,Groovy,Kotlin,我有一个带有Kotlin插件的gradle项目 在我的项目中,我使用groovy和Spock进行测试。 测试中使用的一个实用程序类是用Kotlin编写的,我将它放在src/test/Kotlin中 我试图使用groovy测试中的这个类(Spock规范),我看到“compileTestKotlin”任务首先运行并编译我的实用程序类,但“compileTestGroovy”仍然失败,因为它没有看到它 我怎样才能解决这个问题? 如何将build/classes/kotlin/test/添加到groov
如何将build/classes/kotlin/test/添加到groovy测试的编译类路径?问题是默认情况下
compileTestGroovy
不包括build/classes/kotlin/test
文件夹,因此无法从groovy测试中看到您的kotlin util类
为了修复它,您可以手动将Kotlin测试源添加到compileTestGroovy
的类路径中。将以下内容添加到您的build.gradle
:
compileTestGroovy.classpath += files(compileTestKotlin.destinationDir)
如果生成文件是build.gradle.kts
,请添加以下内容
// make groovy test code depend on kotlin test code
tasks.named<GroovyCompile>("compileTestGroovy") {
classpath += files(tasks.compileTestKotlin)
}
//使groovy测试代码依赖于kotlin测试代码
tasks.named(“compileTestGroovy”){
classpath+=文件(tasks.compileTestKotlin)
}