I am experimenting with the Kotlin DSL and defining common things in buildSrc Kotlin code.
My buildSrc contains a single file Config.kt in buildSrc/src/main/kotlin/build with content:
package build
object UsedVersions {
val kotlin = "1.3.50"
val dokka = "0.9.17"
val gradle_node = "1.2.0"
}
object UsedPlugins {
val kotlin_gradle = "org.jetbrains.kotlin:kotlin-gradle-plugin"
val dokka_gradle = "org.jetbrains.dokka:dokka-gradle-plugin"
val gradle_node = "com.moowork.gradle:gradle-node-plugin"
}
object UsedLibs {
val kotlin_serialization = "org.jetbrains.kotlin:kotlin-serialization"
}
And I have buildSrc/build.gradle.kts containing:
plugins {
`kotlin-dsl`
}
My problem is that when referencing these objects in my project’s build.gradle.kts I have to reference them with a fully qualified name (e.g. build.UsedVersions.kotlin) otherwise (when using UsedVersions.kotlin) I get an Unresolved reference, even though I have some import statements at the top of my build:
import build.UsedVersions
import build.UsedLibs
import build.UsedPlugins
buildscript {
dependencies {
classpath ("\${build.UsedPlugins.kotlin_gradle}:\${build.UsedVersions.kotlin}")
classpath ("\${build.UsedPlugins.dokka_gradle}:\${build.UsedVersions.dokka}")
classpath ("\${build.UsedPlugins.gradle_node}:\${build.UsedVersions.gradle_node}")
classpath ("\${build.UsedLibs.kotlin_serialization}:\${build.UsedVersions.kotlin}")
}
}
plugins {
base
id("org.jetbrains.kotlin.multiplatform") version (build.UsedVersions.kotlin)
}
The funny thing is that IntelliJ Idea is able to autocomplete on UsedVersions, UsedLibs, UsedPlugins and actually added the imports automatically to the build.gadle.kts while doing the autocompletion.
What am I doing wrong? How can I solve this?
Using gradle 5.6.2.