I have a Java project which happens to be built in a recent version (4.13) of the Tridium Niagara framework and is therefore based on Gradle 7.3.1. I’m using Windows 11.
It so happens that Niagara 4.13 has now switched away from using Groovy to Kotlin DSL, so I’m updating my various Gradle-related files accordingly. That update process has gone reasonably smoothly apart from one aspect where I’m having an issue: I want the the copy of gradle.properties in the root of the project to be under git control for sharing with the rest of my team, so I want that file to exclude properties which will be user-dependent and move those elsewhere. It would appear that the accepted advice for the “elsewhere” should be a copy of gradle.properties that each user can put in their own Gradle user home; as long as there are no duplicate properties defined, this should work, yes ? However, I can’t seem to read any properties from that user-local copy.
Here’s what I’ve tried so far.
I place the following property in my project’s copy of gradle.properties:
myProp="CatsMiaow"
At the end of my build.gradle.kts, I have the following code:
val myProp: String = providers.gradleProperty("myProp").get()
println("myProp: " + myProp)
Sure enough, when I execute my build, it prints out the value of ‘myProp’ as CatsMiaow.
I now create gradle.properties in my Gradle user home, i.e.
C:\Users\Gary\.gradle\gradle.properties
and give it just one line:
myProp="Dogs Bark"
I comment out the myProp property in my project’s gradle.properties, add a system environment variable for GRADLE_USER_HOME, and restart everything. I edit the previous build.gradle.kts to add some code to confirm my Gradle user home:
println(providers.environmentVariable("GRADLE_USER_HOME").get())
val myProp: String = providers.gradleProperty("myProp").get()
println("myProp: " + myProp)
When I run this, it correctly picks up my Gradle user home from the Windows environment. However, I get:
Cannot query the value of this provider because it has no value available.
The error disappears if I move the myProp property back to the main gradle.properties.
It appears that the user-local copy of gradle.properties is never being parsed OR I need to read its properties in a different way ? Please - what am I doing wrong ?
Thanks