gradle - 编译 Groovy 和 Kotlin?

标签 gradle groovy kotlin

我正在使用 Groovy 和 Kotlin 开展一个小项目,我的 Kotlin 代码依赖于我的 Groovy 代码,而不是相反。但是,Kotlin 首先编译我的代码而不是 Groovy,因此,我得到了像 Unresolved reference: SiteRepository

这样的错误

有什么建议我可以通过更改构建顺序或明确依赖 Groovy 的 Kotlin 或任何其他建议来解决此问题?

最佳答案

可以这样做:

4.10 之后

Kotlin 优先:

//compileKotlin.dependsOn = compileKotlin.taskDependencies.values - 'compileJava'
compileGroovy.dependsOn compileKotlin
compileGroovy.classpath += files(compileKotlin.destinationDir)
classes.dependsOn compileGroovy

4.10 之前

Groovy 优先:

compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava'
compileKotlin.dependsOn compileGroovy
compileKotlin.classpath += files(compileGroovy.destinationDir)
classes.dependsOn compileKotlin

Kotlin First:

compileKotlin.dependsOn = compileKotlin.taskDependencies.values - 'compileJava'
compileGroovy.dependsOn compileKotlin
compileGroovy.classpath += files(compileKotlin.destinationDir)
classes.dependsOn compileGroovy

需要明确的是,您可以选择您的 Kotlin 代码是依赖 Groovy 还是 Kotlin 上的 Groovy,但您不能同时拥有这两种方式。

关于gradle - 编译 Groovy 和 Kotlin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36214437/

相关文章:

spring-boot - Spring Cloud Streams-以下方法不存在

android - 如何从 Gradle 设置 AAR 输出的名称

grails - 如何调用grails资源插件的 “use”标签作为方法

oracle - Grails .findAll()多次返回同一数据库行,这可能是什么原因引起的?

android - 检测到非 bundle 插件涵盖的未知功能 (Facet[kotlin-language])

android - 仅当添加 AdMob 时应用程序在首次打开时崩溃,但在下次打开时运行正常

android - 避免代码重复 - 如何在 gradle 中创建函数(并调用它们)?

gradle - 未知主机 'downloads.gradle.org'在Android Studio中创建新项目时

grails - gradle:未排序的dependsOn任务,如何处理?

asynchronous - 如何在 Kotlin 中同步检查和设置变量?