https://kotlinlang.org logo
Title
a

Alexander Weickmann

08/08/2019, 4:34 PM
HI all, To reuse Gradle Configuration in subprojects, I would like to declare and then use a function, like is done here: https://github.com/JetBrains/kotlin-wrappers/blob/master/build.gradle#L54 How can I achieve the same in Kotlin DSL?
(not the exact same as the linked method)
a

Alexander Weickmann

08/08/2019, 5:00 PM
thanks, will give it a try 🙂
how can I access classes from other plugins in my buildSrc code? Specifically, I need to code against nu.studer.gradle.credentials.domain.CredentialsContainer
in build.gradle.kts, it is automatically recognized once I apply the plugin ...
g

gildor

08/08/2019, 5:04 PM
Add those plugins to dependencies of buildSrc (buildSrc/build.gradle, dependencies block)
a

Alexander Weickmann

08/08/2019, 5:05 PM
works 🙂
arrr. my gradle build has more code than my actual program
g

gildor

08/08/2019, 5:06 PM
Also if you want to use type safe accessors in buildSrc, use precompiled script plugins (check Kotlin DSL manual for details about it)
a

Alexander Weickmann

08/08/2019, 5:55 PM
fun Project.applyKotlinJs() {
    apply {
        plugin("kotlin2js")
    }
}
and then build.gradle.kts: applyKotlinJs() it works, but once I add project dependencies I get implementation(group = "org.jetbrains", name = "kotlin-react", version = "$reactVersion-pre.80-kotlin-1.3.41") ^ Unresolved reference: implementation
it works when I add the plugin in build.gradle.kts as well
g

gildor

08/09/2019, 2:40 AM
Because you are not using precompiled script plugins, you don't have type safe accessors, so or you use precompiled script plugins, or use dynamic syntax:
"implementation"("org.jetbrains:kotlin-react:$reactVersion")
a

Alexander Weickmann

08/09/2019, 8:07 AM
alright. thank you 🙂