Any way to print currently used arguments/properties?

I would like to print a short kind of debugging log on CI when Gradle wrapper gets executed, to see which properties or arguments are used. Is there a way to do so?

Currently it is sometimes hard to track e.g. what org.gradle.jvmargs are used, when working with project, local and GRADLE_OPTS.

You could have some init script that prints the debug log you want and use that when running builds on CI, e.g. by placing it to <GRADLE_USER_HOME>/init.d/... on the build agent where it will be automatically picked from for all builds.

Thanks for this direction. Is there an API to access e.g. the currently set jvmargs?

Or similar on settings or maybe gradle.

Thanks! I was able to achieve it by adding

settingsEvaluated {

to my init.gradle.kts.

Seems to work fine.

Be careful.
This only works if you give it as project property.
It does not work if you give it as Gradle property.
Even though the method is called gradleProperty it only gives you project properites and in your case you probably set it in some file which makes it a Gradle and project property at the same time which is why you get it.

Hmm, good hint. Maybe then this solution is somewhat error-prone.

In the end I would like to have a reliable output to see the actual setting for max heap size and max metaspace size the Gradle deamon will use/is using.

Was hoping for some Gradle API I can call somewhere.

I thought the solution I initially gave would work, but it indeed also does not work.
Opposed to the provider methods it also looks at extra properties, but still not at Gradle properties.
Both would also give you a value set via -P that is not considered for the daemon at all.

So better just use normal Java API, like Runtime.getRuntime().maxMemory() for max heap.

No idea how to get the max metaspace, but there is for sure also some API.

1 Like

Thanks for your feedback.

I now ended up using these log messages in my root project: net.twisterrob.gradle/runtime.init.gradle.kts at 51a2ace2991721b410bc8498a02dbce2b8208364 · TWiStErRob/net.twisterrob.gradle · GitHub

This covers basically all the infos I care about.

1 Like