Good morning from Germany, I have a complex multi-...
# gradle
s
Good morning from Germany, I have a complex multi-module project that I want to convert from Gradle to Gradle Kotlin DSL. In Gradle I moved common module configuration into separate Gradle files and applied/imported them in each module. With Kotlin DSL this does not seem to work properly. Please see https://gist.github.com/svenjacobs/3643a1ba83def5edf8a07f1d209158ef. It seems that Kotlin scripts applied via
apply(from = "...")
do not evaluate plugins. For instance in
common.gradle.kts
I get an error because
implementation()
is not found. I know that in this case I can use
"implementation"()
but that doesn't solve the actual problem. In other base modules where I load the Android plugin for instance suddenly
android { ... }
is not found. How do I solve this with Kotlin DSL?
g
See previous message, it kinda related
tl;dr; you don’t have static accessors in script plugins, you have a few choices: use dynamic syntax (similar to what you have when write gradle plugin) or use experimental precompiled script plugins
In other base modules where I load the Android plugin for instance suddenly
android { ... }
is not found
To have static accessor you must apply plugin using plugins dsl
But this also work if you apply some plugin that will apply plugin for you, so it will work as transitive dependency
s
I use the plugin DSL like
plugins { id("com.android.application") }
but in the common build script
android
is still not found
g
common build script also must apply it with plugins dsl
but problem that script plugins do not support plugins dsl yet
so the only similar way is to use precompiled script plugins that support type safe accessors and plugins dsl, but they are experimental and not everything work as expected
s
Hmm, I try to use
buildSrc
instead but how do I configure the
android
block for instance in a
fun Project.androidProject()
?
g
there are other ways to do that
first: you don’t have static accessors in simple buildSrc/src/kotlin source code
but you can add Android plugin as dependency to your buildSrc project and use it using standard Gradle plugins API like
project.extension<EXTENSION_TYPE>.configure
s
Okay, I will try this way
g
precompiled script plugins is another way, they support static accessors and plugins dsl, but as I said not everything work for now
s
FYI I migrated the whole project to Kotlin DSL, moving common configuration into
buildSrc
. It was quite some work and I still have a few minor issues but all in all the project compiles and it was worth it! 😄
n
@gildor can you point me to some docs of precompiled script plugins ?