https://kotlinlang.org logo
Title
b

Bernhard

11/21/2018, 9:36 AM
the preferred way to store variables for versions is in buildSrc, but what if my buildSrc also requires variables? buildSrcBuildSrc/?
g

gildor

11/21/2018, 9:38 AM
What is exactly requires variables,
buildSrc/build.gradle
or some code in
buildSrc/src
?
b

Bernhard

11/21/2018, 9:38 AM
versions,e.g. for spring boot to align all deps
implementation(“org.springframework.boot😒pring-boot-starter-actuator:${Versions.springBootVersion}“)
g

gildor

11/21/2018, 9:39 AM
and where do you have those dependencies? In
buildSrc/build.gradle
?
b

Bernhard

11/21/2018, 9:39 AM
in build.gradle.kts and buildSrc/build.gradle.kts
the ones in buildSrc are basically for custom gradle tasks
g

gildor

11/21/2018, 9:40 AM
Then the only way to move them to some external config, such as gradle.properties and read
b

Bernhard

11/21/2018, 9:41 AM
not a fan of that, I’d like to keep that on .gitignore because you can also configure stuff like java path
g

gildor

11/21/2018, 9:41 AM
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

Bernhard

11/21/2018, 9:42 AM
org.gradle.java.home=C:/Program Files/Java/jdk1.6.0_45 org.gradle.jvmargs =-XX:MaxPermSize=64m
for instance
g

gildor

11/21/2018, 9:42 AM
anyway, you always can have some custom config file
b

Bernhard

11/21/2018, 9:42 AM
can I just parse a JSON file?
g

gildor

11/21/2018, 9:42 AM
Any config file
that can be read by build script
b

Bernhard

11/21/2018, 9:43 AM
is there a way to parse the file only once
and not on each access?
g

gildor

11/21/2018, 9:43 AM
once? Per Gradle run?
b

Bernhard

11/21/2018, 9:43 AM
like on gradle start parse it into a “global”?
g

gildor

11/21/2018, 9:44 AM
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

Bernhard

11/21/2018, 9:45 AM
hm, ok, thank you
singleton I guess then
g

gildor

11/21/2018, 9:46 AM
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

Bernhard

11/21/2018, 9:53 AM
right, but it would be fine if it was parsed twice