I'm trying to create a Kotlin convention script pl...
# gradle
i
I'm trying to create a Kotlin convention script plugin similar to the Java one in Example 19 here: https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:kotlin-dsl_plugin Project: https://github.com/ianbrandt/multi-kotlin-project Code: https://github.com/ianbrandt/multi-kotlin-project/blob/49cdae7f3f782af51d9d511b994b0fb412d9a8d5/buildSrc/src/main/kotlin/kotlin-project.gradle.kts I'm getting the following errors:
Copy code
> Task :buildSrc:compileKotlin FAILED
e: multi-kotlin-project/buildSrc/src/main/kotlin/kotlin-project.gradle.kts: (2, 22): Unresolved reference: kotlin
e: multi-kotlin-project/buildSrc/src/main/kotlin/kotlin-project.gradle.kts: (9, 2): Unresolved reference: implementation
e: multi-kotlin-project/buildSrc/src/main/kotlin/kotlin-project.gradle.kts: (13, 11): Unresolved reference: KotlinCompile
e: multi-kotlin-project/buildSrc/src/main/kotlin/kotlin-project.gradle.kts: (13, 26): Type mismatch: inferred type is () -> TypeVariable(_L) but Class<TypeVariable(S)> was expected
e: multi-kotlin-project/buildSrc/src/main/kotlin/kotlin-project.gradle.kts: (14, 3): Unresolved reference: kotlinOptions
The intent is to have a multi-project build where standardized Kotlin, Java, etc. plugins and configuration can be mixed into child projects as needed. Any ideas as to what I'm doing wrong?
m
i've found that when writing convention plugins like this, you need to declare them as dependencies in
buildSrc
so they are available on the classpath i think https://github.com/gradle/gradle/issues/9240 is the right open issue to provide better compiler output when trying to declare the version so in
buildSrc/build.gradle.kts
you have something like
Copy code
dependencies {
  // taken from <https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm>
   implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31")
}
https://github.com/gradle/gradle/issues/9282 is for improving the dependency declaration then, in your
kotlin-project.gradle.kts
just omit the version
Copy code
plugins {
  kotlin("jvm")
}
i
That fixed it, thanks! I’ve updated the sample project files: https://github.com/ianbrandt/multi-kotlin-project I’d still welcome feedback as to whether everything I’m doing there is best practice, but it works, and everything is green in IntelliJ.