I’m experimenting with replacing Gradle plugins currently written in Groovy with Kotlin.
In a such a project where Groovy class A references Kotlin class B, a gradlew clean build
will fail with:
example\misc-gradle-tasks>gradlew clean build
> Task :compileKotlin
Using kotlin incremental compilation
> Task :compileGroovy
startup failed:
example\src\main\groovy\A.groovy: 44: unable to resolve class B
@ line 44, column 5.
@Internal
^
FAILURE: Build failed with an exception.
After some experimentation, I’ve found I can work around this by manually specifying this task dependency:
compileGroovy.dependsOn 'copyMainKotlinClasses'
Is there already a bug for this? Or is there some other step which should be taken to properly mix groovy and kotlin in the same project?
For reference:
Gradle version 4.0.1
sample buildscript:
plugins {
id 'groovy'
id("org.jetbrains.kotlin.jvm").version("1.1.3-2")
}
compileGroovy.dependsOn 'copyMainKotlinClasses'
dependencies {
compile gradleApi()
compile ("org.jetbrains.kotlin:kotlin-stdlib:1.1.3-2")
testCompile gradleTestKit()
testCompile ('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude module: 'groovy-all'
}
}