Groovy中的测试类在Kotlin中看不到测试类 [英] Test classes in Groovy don't see test classes in Kotlin

查看:84
本文介绍了Groovy中的测试类在Kotlin中看不到测试类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Kotlin插件的gradle项目.

I have gradle project with Kotlin plugin.

在我的项目中,我使用groovy和Spock进行测试. 用Kotlin编写的用于测试的实用程序类之一,我将其放在src/test/kotlin

In my project I uses groovy and Spock for tests. One of utility classes used in tests in written in Kotlin and I put it to src/test/kotlin

我正在尝试使用Groovy测试(Spock规范)中的此类,我看到"compileTestKotlin"任务首先运行并编译了我的实用程序类,但是"compileTestGroovy"仍然失败,因为它没有看到它.

I'm trying to use this class from groovy tests (Spock specification), I see that "compileTestKotlin" task runs first and compiles my utility class, but still "compileTestGroovy" fails, because it does not see it.

如何解决这种情况? 如何在groovy测试的编译类路径中添加build/classes/kotlin/test/?

How can I fix this situation? How to add build/classes/kotlin/test/ to the compilation classpath of groovy tests?

推荐答案

问题是默认情况下compileTestGroovy不包含build/classes/kotlin/test文件夹,因此从Groovy测试中看不到您的Kotlin util类.

The issue is that by default compileTestGroovy doesn't include build/classes/kotlin/test folder, so your Kotlin util class cannot be seen from Groovy tests.

为了修复它,您可以手动将Kotlin测试源添加到compileTestGroovy的类路径中.将以下内容添加到您的build.gradle:

In order to fix it you can manually add Kotlin test sources to compileTestGroovy's classpath. Add the following to your build.gradle:

compileTestGroovy.classpath += files(compileTestKotlin.destinationDir)

如果您的构建文件是build.gradle.kts,请添加以下内容

If your build file is build.gradle.kts, add the following

// make groovy test code depend on kotlin test code
tasks.named<GroovyCompile>("compileTestGroovy") {
    classpath += files(tasks.compileTestKotlin)
}

这篇关于Groovy中的测试类在Kotlin中看不到测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆