the preferred way to store variables for versions ...
# gradle
b
the preferred way to store variables for versions is in buildSrc, but what if my buildSrc also requires variables? buildSrcBuildSrc/?
g
What is exactly requires variables,
buildSrc/build.gradle
or some code in
buildSrc/src
?
b
versions,e.g. for spring boot to align all deps
implementation(“org.springframework.bootspring boot starter actuator${Versions.springBootVersion}“)
g
and where do you have those dependencies? In
buildSrc/build.gradle
?
b
in build.gradle.kts and buildSrc/build.gradle.kts
the ones in buildSrc are basically for custom gradle tasks
g
Then the only way to move them to some external config, such as gradle.properties and read
b
not a fan of that, I’d like to keep that on .gitignore because you can also configure stuff like java path
g
Or just define in
buildSrc/build.gradle
and pass as system properties or some similar mechanism and use for your
Versions
class
java path in Gradle config?
b
org.gradle.java.home=C:/Program Files/Java/jdk1.6.0_45 org.gradle.jvmargs =-XX:MaxPermSize=64m
for instance
g
anyway, you always can have some custom config file
b
can I just parse a JSON file?
g
Any config file
that can be read by build script
b
is there a way to parse the file only once
and not on each access?
g
once? Per Gradle run?
b
like on gradle start parse it into a “global”?
g
You can parse it in build script and try to pass some properties to code, but probably just read it second time is easier
b
hm, ok, thank you
singleton I guess then
g
But you cannot have singleton shared between your buildSrc/build.gradle and buildSrc/src/*
Of course you can cache result of parsing, but you problem, as I understand, that you need the same data in config and source files of buildSrc
b
right, but it would be fine if it was parsed twice