我正在开发一个结合了 groovy
和 kotlin
的项目。
我的 Kotlin 类需要来自 groovy 部分的对象,我怎样才能让 gradle 在 kotlin 之前编译 groovy?
我正在使用 Gradle 6.3
和 kotlin-dsl
我尝试了几种解决方案:srcsets order, tasks order, ... 似乎没有任何效果
有什么想法吗?
最佳答案
感谢tim_yates ! (为什么这个文档没有出现在谷歌😧)
这里是kotlin
和groovy
的文档改编
tasks.named<AbstractCompile>("compileGroovy") {
// Groovy only needs the declared dependencies
// (and not longer the output of compileJava)
classpath = sourceSets.main.get().compileClasspath
}
tasks.named<AbstractCompile>("compileKotlin") {
// Java also depends on the result of Groovy compilation
// (which automatically makes it depend of compileGroovy)
classpath += files(sourceSets.main.get().withConvention(GroovySourceSet::class) { groovy }.classesDirectory)
}
关于kotlin - Gradle 6+ : compile groovy before kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61138147/