Does anyone have an example of a real world multi-...
# gradle
c
Does anyone have an example of a real world multi-file Kotlin based gradle build? Especially with using plugins in the non-
build.gradle.kts
files? I'm a complete newbie to the Kotlin DSL and struggling with getting plugins to work in a
foo.gradle.kts
file, and it would be nice to see how others have done it.
g
What do you mean “multi-file Kotlin based gradle build”? Do you mean with
apply(from="foo.gradle.kts")
?
It’s not the best way to share logic with Kotlin DSL, use buildSrc instead
there is a bunch of good examples on kotlin-dsl github https://github.com/gradle/kotlin-dsl/tree/master/samples
But you still can use script plugins (include gradle files) if you want, it can be helpful if you migrate from groovy to kotlin, if you need this, check samples on kotlin-dsl repo
c
Yeah, it was using
apply(from="foo.gradle.kts")
. I've got a lot of tasks, more so than actual logic, so I thought it was more reasonable for them to be in
.gradle.kts
file(s). The samples repo shows using multiple
.kts
files, but doesn't show anything about using plugins in those included files, and that's where I'm hitting unresolved symbol errors
g
yes, plugins application doesn’t work for now in script plugins
Use buildSrc for such tasks instead (add plugins as dependencies to buildSrc), you can find examples of this approach on kotlin-dsl github
c
Ah, right. What I want to do is something like this project: https://github.com/gradle/kotlin-dsl/tree/master/samples/modularity but be able to create tasks from plugins. So do you mean this isn't supported right now?
g
This is supported, but not with
plugins{}
dsl, so you cannot use any type safe API of Kotlin DSL. There are some other ways, use buildscript or add plugins as dependencies to buildSrc (will be available in script plugins too)
c
OK, I think I've got it. I'll look to see how I can restructure things to use
buildSrc
and whatnot. Thanks for the help!
g
Please ask if you have additional questions about this 👍 And check migration guide, it’s very helpful document
👍 1