How to use a user-local gradle.properties instead of the project one

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

Besides that the quotes in a properties file are wrong, unless you really want them as part of the value, what you do seems fine.

Besides that you do not need to set GRADLE_USER_HOME if you want the default location to be used which is .gradle/ in your USER_HOME.

Maybe make sure by using println(gradle.gradleUserHomeDir.absoluteFile) instead of just reading the environment variable what Gradle user home you have set. Using providers.gradleProperty is fine to get those properties from the user-specific file.

Thank you ever so much !

The extra quotes were my fault when I posted my question: they are not really there in the properties files !

I knew about the default setting for GRADLE_USER_HOME but I wanted to try setting it explicitly because I couldn’t get it to work.

The problem was something in the end that I should have checked and completely forgot: my IntelliJ project setting for the Gradle user home was an old bespoke one which had an explicit (wrong) path. As soon as I restored it to the default user home, everything worked.

My apologies, but thanks again for telling me to print out the absolute path !

Gary

Bjorn,

Can I ask one other thing ?

The approach of adding a gradle.properties to user home is fine, but if there’s a property inside there which is used by MANY projects that the user is going to work on, then that property will affect all such projects.

Instead, is there a way of having user-specific Gradle properties in a project so that they affect ONLY that one project but can still be separated out into a separate git-ignored file which is located inside the project hierarchy ?

Thanks

Can I ask one other thing ?

Sure, if you stop raping my name.
It is Björn or Bjoern, not Bjorn.

if there’s a property inside there which is used by MANY projects that the user is going to work on, then that property will affect all such projects.

Correct

is there a way of having user-specific Gradle properties in a project so that they affect ONLY that one project

No.
If you have own properties, you can name-space them with the project name for example.
But if it is about standard properties or properties of 3rd party plugins, no.

The feature request, though imho more a bug that it is missing, was at Add official local.properties support · Issue #12283 · gradle/gradle · GitHub but was denied. And any 3rd party plugin cannot help with that, as there is not yet any way to set a project property by code. You can only set extra properties which override project properties, but only if project.getProperty and friends are used. If providers.gradleProperty is used, those are not considered.

Understood, thank you.

Should have gone to Charset to produce the o with added diaeresis and I didn’t - that was lazy of me, and I owe you an apology. Sorry :face_with_open_eyes_and_hand_over_mouth:

Sorry, Björn, for saying this, but I don’t think there is a reason to get offended by this, some people don’t have accents on their keyboards, it’s definitely not rape, but a technical limitation: it’s actually a common thing among international people to type names without characters not present on their keyboard. Imagine talking to Chinese, Japanese, Korean, etc. people whose name can’t even be typed at all using Latin keyboard layouts! Sure you could say they could have used the clipboard, which is a valid point, but in today’s web pages where everything is clickable, you’re lucky if text selection works at all, which happens to do here (and that’s what I did), but many pages just annoy you, and that’s what causes people to follow the least resistance everywhere, but even then, we got mentions like @Vampire too, which is also well accepted and trending, and it’s every easy to type, and reduces the probability of making mistakes.

but I don’t think there is a reason to get offended by this

I’m not offended.
It is a simple fact that my name is not Bjorn, and I like being called by my correct name, not some random mutant of it.
It is like if I were calling you Christian instead of Krisztián (if that is the correct spelling of your name).
You might not mind being called by random variants of your name, but I do and ask you to respect that, not criticising me for criticising people misspelling my name.

some people don’t have accents on their keyboards

That is not at all an excuse, especially as there are enough correct alternatives. They can use my nickname, which is special-characters free, and they can use the correct “oe” transcription of “ö” that you can type with virtually any keyboard, and if they really want to use the correct name and have no special character, they can still copy and paste the name.
But being too lazy to type “oe” and thus just typing “o” is not correct, and that’s a simple fact.

it’s actually a common thing among international people to type names without characters not present on their keyboard

That would then be Bjrn and not any better. :stuck_out_tongue_winking_eye:
As mentioned above, there are enough correct alternatives to not need intentionally misspelling my name.

Imagine talking to Chinese, Japanese, Korean, etc. people whose name can’t even be typed at all using Latin keyboard layouts!

That is not in any way any excuse.
Usually those people have latin-character versions of their names or latin-character nicknames that people can use.
So do I.
And if would want to use their correct name, I could anytime copy & paste it.

you’re lucky if text selection works at all

I’ve not yet seen any page where I couldn’t copy the text I wanted to copy.
Besides that - as I even said before your pointless criticism - you can just use latin characters to properly address me in at least two ways.

but even then, we got mentions like @Vampire too, which is also well accepted and trending, and it’s every easy to type, and reduces the probability of making mistakes.

Yes, and that’s perfectly fine.
Using my nick is also perfectly fine, that’s what I have it for.
It is also fine to use my real name, but then correctly or with the correct ASCII-only transcription and not with a typo.

So again,
I have no idea why you feel you have to post this pointless criticism in a one-year old public thread.
I don’t want to be adressed with that horrible non-version of my name and ask you to respect that, thanks.

I want to clarify that my intention wasn’t to criticize you personally or dismiss your preference — I genuinely respect that you want your name spelled correctly.

However, from my understanding, it should be generally acceptable to suggest a correction in a forum topic — even if the conversation is a year old — as long as it’s done respectfully and constructively, which is what I aimed to do.

I’m honestly hurt by being told my input was “pointless criticism.” I took time to explain a broader context that I believed was relevant and helpful, and I did so respectfully.

I understand that the correct spelling of your name is important to you, and I’ll honor that. But I also ask that my perspective be treated with the same respect I tried to show yours.

PS.: When I wrote, “to type names without characters not present on their keyboard”, I think I made a mistake. You’re right, I should have written “to type names without accents due to characters not present on their keyboard”.

However, from my understanding, it should be generally acceptable to suggest a correction in a forum topic — even if the conversation is a year old — as long as it’s done respectfully and constructively, which is what I aimed to do.

I’m honestly hurt by being told my input was “pointless criticism.” I took time to explain a broader context that I believed was relevant and helpful, and I did so respectfully.

I understand that the correct spelling of your name is important to you, and I’ll honor that. But I also ask that my perspective be treated with the same respect I tried to show yours.

I’m sorry, my words were not what was intended. I meant pointless regarding the thread topic, so “off-topic” would have been the better choice of words. This thread is not about how to correctly spell my name but about user-local gradle.properties files. My line about my name was just a side-note to the author who misspelled my name. A broader discussion about this is not really on-topic here and should probably have been a direct message instead. :slight_smile: