https://kotlinlang.org logo
Title
c

christianbecker

11/18/2018, 1:40 PM
Should the classpath of the build script be shared with all
.gradle.kts
files that will be included via
apply { from("tasks.gradle.kts") }
? I've extracted some build logic into this new
tasks.gradle.kts
file, but unfortunately, I can't reference any class from the original classpath of the
build.gradle.kts
. Is this intended? If so, is there any way to make the classpath available to the
tasks.gradle.kts
file?
g

gildor

11/18/2018, 9:09 PM
Because tasks.gradle.kts can be included everywhere, you don't have access to particular build.gradle.kts class path There is an issue to add support plugins block for script plugins to allow define it. For now as I understand you can use onle buildscript dsl, so no access to statically typed accessors https://github.com/gradle/kotlin-dsl/issues/432 In general recommended way to extract parts of configuration is buildSrc
c

christianbecker

11/19/2018, 10:24 AM
Thanks, so classes in
buildSrc
should have access to the same classpath? Or how can I achieve that?
@gildor: Friendly ping 🙂
g

gildor

11/20/2018, 1:17 PM
Sorry, missed your message. buildSrc has own build.gradle file, so you can add any plugins as dependency to buildSrc project and plugin will be in class path of all files in your project.
And in general, instead extracting parts of config to not type safe script plugins you can define binary plugin and just apply it as any other plugin
You even can provide extension for configuration
Or, even without plugin, you can just define a function in buildSrc with configuration
c

christianbecker

11/21/2018, 10:30 AM
Thanks. My error was that I wasn't removing the classpath entry from the normal
build.gradle.kts
after adding the dependency to the
buildSrc/build.gradle.kts
.