Gradle 6+:在 kotlin 之前编译 groovy

yod*_*mad 3 groovy gradle kotlin build.gradle gradle-kotlin-dsl

我正在研究一个结合groovy和 的项目kotlin。我的 Kotlin 类需要来自 groovy 部分的对象,我怎样才能使 gradle 在 kotlin 之前编译 groovy ?

我正在Gradle 6.3使用kotlin-dsl

我尝试了几种解决方案:srcsets 顺序、任务顺序...似乎没有任何效果

任何想法 ?

yod*_*mad 5

感谢蒂姆_耶茨!(为什么这个文档没有出现在谷歌上)

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)
}
Run Code Online (Sandbox Code Playgroud)