I have the following dependency in my gradle file,...
# gradle
e
I have the following dependency in my gradle file, but now I'd like to move it into a plugin in buildsrc. What's the correct way to achieve this?
Copy code
dependencies {
  implementation(platform("com.google.firebase:firebase-bom:27.0.0"))
}
v
What's the concrete part you are struggling with?
e
What I've found so far is:
Copy code
dependencies.platform("com.google.firebase:firebase-bom:${Versions.Android.firebaseBom}")
but I don't see how I can do that in the `implementation`configuration.
v
Are you writing a precompiled script plugin or a "normal" binary plugin?
e
I'm not sure 😅
v
Is it a kts or a kt file?
e
It's in the same project, in a kotlin file in
buildSrc
v
Is it a kts or a kt file?
e
kt
v
I'd recommend using a precompiled script plugin instead, they are written almost like normal build scripts
e
How does that work?
Basically use the
kotlin-dsl
plugin in
buildSrc/build.gradle.kts
and then have
foo.gradle.kts
files in your kotlin source set. In there you write almost like in normal build scripts and you can apply it using the id
<package statement>.<filename without .gradle.kts>
.
e
Thanks! Does that mean there's no way to do it in the normal binary plugin?
m
Not sure if that helps but
implementation(foo)
is a generated accessor for
add("implementation", foo)
. This was a big ahah moment when I realized that
e
Oh so something like this would do it?
Copy code
dependencies.add("implementation", dependencies.platform("com.google.firebase:firebase-bom:${Versions.Android.firebaseBom}"))
m
yea, most likely. I'm not super familiar with the platform stuff but configurations are all string-based behind the scenes
v
Yes, that should do
👍 1
You can do anything in a normal binary plugin
e
Cool, I knew that
add("implementation", ...)
was getting used under the hood, but I didn't realize you could pass a dependency to
add
v
precompiled script plugins are just a ton easier to write 😄
e
I'm gonna test that out after I finish this one. I'm porting a large project to gradle kotlin, and it was fun until I realized that plugins are the way to go 😃