i’m migrating from groovy to kotlin and i have a question about extensions. I would like to create an extension in a kotlin file under
buildSrc
and access that extension from all the gradle scripts in my project. I was under the impression that it was possible since all files under
buildSrc
are automatically added to the class path but it doesn’t seem to work for me. When i define the extension in the same class as its usage, it works fine
build.gradle.kts
repositories {
myExtension()
}
fun RepositoryHandler.myExtension(): MavenArtifactRepository =
maven {
// Some code
}
But if i define the extension in another file, i can’t seem to get it to work as here:
build.gradle.kts
import extensions.myExtension
repositories {
myExtension()
}
buildSrc/src/main/kotlin/extensions/MyExtensionFile.kt
package extensions
// some imports
fun RepositoryHandler.myExtension(): MavenArtifactRepository =
maven {
// Some code
}
Specifying the extension in another file yields -
Unresolved reference: extensions
.Is it possible to have such a setup with reusable extensions accessible from all the gradle files?