GRADLE_OPTS is not really about Gradle command line arguments but about VM options

in the official documentation it is written that

GRADLE_OPTS: Specifies command-line arguments to use when starting the Gradle client. This can be useful for setting the properties to use when running Gradle.

but when I want to set some (default) command line parameters like --debug or --stacktrace, I get an error. Which happens because GRADLE_OPTS is not about command-line arguments for Gradle, but about arguments for the VM running Gradle (like -Xmx512m).

WORKS: GRADLE_OPTS=“-Xmx512m” gradlew assemble
FAILS: GRADLE_OPTS=“–debug” gradlew assemble

So I think the official documentation is quite misleading and should be fixed.

But besides this, is there any way to accomplish what is actually described in the documentation, namely to define the command-line arguments for Gradle as environment variable?

Background is that I want to integrate the Gradle command into our continuous integration environment (GoCD), and there, the simplest way is just to invoke the “./gradlew” command, but I don’t want to repeat the standard Gradle command line parameters like:
–stacktrace
–no-daemon
–continue
–gradle-user-home
etc…

for any command. I would like to store this as environment variable. And I don’t want to make myself dependent on GoCD and implement a custom plugin…

4 Likes

It is finally fixed: https://github.com/gradle/gradle/issues/7491

Hi there

The documentation is now clear, but there is no description to solve your request.
Because I only use the GIT-BASH I can create some BASH-ALIAS

alias gw=“./gradlew --console=plain --build-cache --parallel”

And I add this line to my local bashrc:

echo ‘alias gw=“./gradlew --console=plain --build-cache --parallel”’ >> ~/.bashrc

Now I can shorten any call to the gradle-wrapper like in

gw build