Hi I want to move some versions into a configurati...
# gradle
b
Hi I want to move some versions into a configuration so that I can use that in both buildSrc and src. I thought about moving it to the settings.gradle.kts. Does buildSrc have access to that and how do I use settings in my build.gradle.kts?
g
what is “src”? You want to use it on runtime of your application?
or you just want to use version in buildSrc/build.gradle?
b
I have deps that line up with my application and build (e.g. junit)
I don't want to bump the same version twice
g
Yeah, there is easy way. Only parse some properties file in buildSrc/build.gradle and do the same in buildSrc/src You can also parse only once, and set sytem property, but not sure that it’s good way
I would create an issue on Gradle issue tracker, looks as popular feature request
b
can I name the properties file something other than project.properties?
g
Yes, it can be any properties file
b
Is there something built in like: val kotlinVersion by properties("../file.properties")
g
this file will not be parsed automatically. you have to do that manually (there is a class for that)
k
To this I end I tend to generate source in buildSrc so the properties file only has to be parsed once (the main build.gradle.kts itself has the generated class on the classpath): https://github.com/FTSRG/theta/blob/750815bbdcedcd3826ddbcb3ddbc030280d7151b/buildSrc/build.gradle.kts#L46 I should probably extract this into a plugin, though.
g
You need something like that
Properties().load(File("some.properties").reader())
Not sure that this approach is better
b
the whole thing would be a non issue for me if managing deps was as neat as in node.js (e.g. locking version ranges)
g
Gradle has version locking and ranges
b
ok, nvm then 🙂
Not exactly about versions, but just allow to have complicated resolution rules. Usual ranges is just about using wildcards for versions https://docs.gradle.org/current/userguide/customizing_dependency_resolution_behavior.html