I'm migrating a project to using the modern gradle...
# community-support
c
I'm migrating a project to using the modern gradle plugins block to define plugins. Im still using groovy though... not allowed to use kts. it seems like its not allowed to define a variable (like for a kotlin version number). and then reference that in my plugins. is that right? seems crazy to me, but just want a sanity check.
v
You mean defining a variable before
plugins { ... }
and using it inside?
The
plugins { ... }
block is extracted and evaluated separately, so it cannot use anything outside the block.
c
doesn't really matter to me whether its inside or out. i just have two plugins that can have the same kotlinVersion as a variable and I can't seem to define a variable inside or out.
v
Ah, yeah, long ago I used Groovy DSL. The plugins block there is way more restricted.
You can either put the property to the
gradle.properties
, or you could abuse a
buildscript
block and
ext
properties like
Copy code
buildscript {
   ext.foo = '+'
}

plugins {
   id "foo" version "$foo"
}
e
version catalog works with groovy too
v
Ah, yes, of course that's the right recommendation, should get some sleep 🙂
c
cant use version catalog yet... so I will use the buildcript suggestion! thanks! hopefully in about a month or so we'll be transitioning to toml and/or kts so ill update then.
👌 1
👍 1
y
You can either put the property to the
gradle.properties
, or you could abuse a
buildscript
block and
ext
properties like
gradle.properties
is definitely the way to go in your case. It is a good intermediate to go before stepping to the version catalog.
m
Curious why you can't use a version catalog. You don't have to put all your dependencies there, you can start with just your plugins
e
or even just versions
it's not much different than putting them in gradle.properties at that point but it is a starting point
💯 1
v
He can also use to port just one file to Kotlin DSL. But if company landscape says no, you often have no choice.
c
yeah. not my circus unfortunately. and the TL has... opinions. lol
🙄 1
😮 1
v
Send him to me, then he has mine 😄
😄 2