Folks, I'm having a very hard time adding kotlin support to a multi-project gradle build. Details in...
g
Folks, I'm having a very hard time adding kotlin support to a multi-project gradle build. Details in thread.
I have two gradle projects in an intellij project, a cli application that depends on a core library. Both in java. I set out to add kotlin, because obviously I'd rather be coding in kotlin than java, and my team didn't care either way.
I added the kotlin line to the plugins for the cli. This worked exactly as I expected, and I was able to convert the two cli classes to Kotlin, build, run, and release, no problems.
When I added the same line to the core project, however, I get the attached error.
Any clues? Some things I've tried: adding a build.gradle.kts to the root and putting the line there, then removing the versioning from the other two. Dropping the line in cli and only adding the line in core. Yelling at my dogs to be quiet and let me think. I have examined the stack trace, but, as usual with gradle stack traces, it is 1000 lines of illegible text to me. The project is JDK 17, as is the Gradle JVM.
The error occurs on just a ./gradlew clean
I note there's an open gradle feature request to improve that error message by describing what the current context actually is, but as I say, it's open.
e
try using
Copy code
plugins {
    kotlin("jvm") version "1.9.23" apply false
}
in the root project, and
Copy code
plugins {
    kotlin("jvm")
}
in app and core?
that is needed for multiplatform projects at least, doesn't look like you're hitting the build service issue but in case that makes any difference
stack trace should still help point out whether it's a plugin issue or a build script issue
g
Okay, I now have a root project with an apply-false of the kotlin-jvm, and the two subprojects just say kotlin("jvm") with no further info. Same result. Stack trace attached.
e
ok that points to a piece of code in KGP that does
Copy code
project.configurations.maybeCreateResolvable(PLUGIN_CLASSPATH_CONFIGURATION_NAME).apply {
            isVisible = false
            addGradlePluginMetadataAttributes(project)
        }
which can break if there's anything in your buildscripts that is resolving configurations too early
are your build scripts or any other plugins doing anything with
configurations.all
or similar?
g
The core project is as simple as gradle scripts get.
Ooooooh, a clue. The cli build has some graalvm stuff in it. I stripped it out, and now everything compiles and runs.
Hmmm. I was planning to move this app to conveyor distribution instead of graalvm. Looks like I might do that sooner rather than later. (I'm not entirely sure how well conveyor works with CLI apps, but I am impressed by how much they've done with it in such a short time.)
Thanks for your help on this, @ephemient!