Hey everyone!
I have a question about Gradle configuration with Kotlin DSL in Android project.
I want to set the classpath of the project in "remote"(plugin, etc?) way ¿Is it possible? ¿Does anyone know how to do it?
v
Vampire
06/06/2022, 5:55 PM
It's probably possible, but at least to me it is unclear what you are asking. Can you elaborate on what you mean?
g
Guido Perre
06/06/2022, 5:59 PM
Of course. I have a multi-module project on Android and I want to have a single unified build script across all modules, mainly to avoid problems with plugins like hilt or changing the kotlin version in all repositories at the same time.
v
Vampire
06/06/2022, 6:01 PM
Yep, sounds like you want to write and possibly publish a convention plugin. You can write it as precompiled script plugin or as conventional plugin.
g
Guido Perre
06/06/2022, 6:15 PM
I tried creating a classpath.gradle.kts and apply it in build.gradle.kts like this:
but i have no luck 😞
I also created a plugin that sets the buildscript block but I get the following error message:
Cannot change dependencies of dependency configuration ':classpath' after it has been resolved.
v
Vampire
06/06/2022, 8:51 PM
That apply seems pretty misplaced and syntactically wrong. As you have a script plugin there, it would be with
apply(from = "...")
and most likely outside the
buildscript
block. But I strongly advise against traditional script plugins, especially with Kotlin DSL as you there do not get the type-safe accessors generated. Instead you should use precompiled script plugins in an included build or, if you prefer,
buildSrc
. And you should read the documentation as it advised.
Just trying out stuff blindly of course does not work. But hey, an hour of trial and error can save you 5 minutes reading documentation. 😉
g
Guido Perre
06/06/2022, 10:30 PM
Thanks for your answer. I was trying to solve that problem with stackoverflow or medium blogs, but it's true that i should read the documentation to get it. Do you have a link to get started? I saw that the gradle documentation is quite large and I just want to focus on my problem
v
Vampire
06/06/2022, 11:09 PM
I'm on mobile, but the docs have a pretty good search and I intentionally gave you the proper buzzwords for it. 😉