Hey everyone! I have a question about Gradle conf...
# gradle
g
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
It's probably possible, but at least to me it is unclear what you are asking. Can you elaborate on what you mean?
g
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
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
I tried creating a classpath.gradle.kts and apply it in build.gradle.kts like this:
Copy code
buildscript {
  apply("gradle/classpath.gradle.kts")
}
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
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
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
I'm on mobile, but the docs have a pretty good search and I intentionally gave you the proper buzzwords for it. 😉
❤️ 1