samuel
12/21/2020, 2:10 PMbuildSrc
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?Vampire
12/21/2020, 3:12 PMpackage extensions
in your MyExtensionFile.kt
, don't you?samuel
12/21/2020, 3:13 PMVampire
12/21/2020, 3:21 PMVampire
12/21/2020, 3:21 PMsamuel
12/21/2020, 3:22 PMVampire
12/21/2020, 3:23 PMprintln("FOO")
to the extension and executed the help
taskVampire
12/21/2020, 3:23 PMFOO
was printed, build successfulVampire
12/21/2020, 3:24 PMsamuel
12/21/2020, 3:26 PMsamuel
12/21/2020, 4:08 PMUnresolved reference: extensions
samuel
12/21/2020, 4:24 PMVampire
12/21/2020, 4:25 PMbuildSrc/build.gradle.kts
? Because that is expected.Vampire
12/21/2020, 4:25 PMbuildSrc/build.gradle.kts
defines how to build the stuff in buildSrc/src
so you cannot use things from buildSrc/src
in the definition of how to build it.Vampire
12/21/2020, 4:26 PMsamuel
12/21/2020, 4:33 PMbuild.gradle.kts
work perfectly fine, thank you for the help 😃Vampire
12/21/2020, 4:33 PM