Unix start script doesn't respect JAVA_OPTS when xargs isn't installed #19682
Description
Expected Behavior
- Given I have a Java application that has been built and packaged using the
distribution
plugin - and I build a docker image containing the application along with a minimal OS
- and I set the image's entrypoint to be the Unix start script generated by Gradle
- and I set some configuration in the
JAVA_OPTS
environment variable - When I start the container
- Then I expect that my
JAVA_OPTS
configuration should be included in the command line used to launch the java process
Current Behavior
The Unix startup script uses xargs
"to parse quoted args". The minimal OS image I'm using doesn't contain xargs
. When I run the startup script, I see a warning:
line 233: xargs: command not found
At this point I expect the script to fail. However, the script continues and the application starts up anyway. JAVA_OPTS
is not included in the command line.
Context
I use JAVA_OPTS
to set the heap size appropriately for the size of the container I'm deploying. For example, in a 1GB container I might set JAVA_OPTS=-Xmx700m
, to allocate 700 megabytes of heap and leave 300 megabytes of headroom. This worked fine under Gradle 6.
After upgrading to Gradle 7, the application doesn't respect JAVA_OPTS
and starts up with the default amount of memory, which is 1/4 of the available memory. In my 1GB container, the application starts up with 250MB of heap.
My automated tests didn't catch the issue, because the container still starts up fine and has enough memory to respond to requests. The application only starts to fail when deployed and under load.
If the start script requires xargs
, I expect it to fail when xargs
is not installed.
Steps to Reproduce
https://github.com/roomscape/gradle-start-script
The linked repository contains a Gradle application and a Dockerfile that reproduces the problem. I reproduced the problem in docker since it's an easy way to create an environment where xargs
isn't installed.
When running the docker container with --env JAVA_OPTS="-Dfoo=bar"
, the application should print out
Application was started with -Dfoo=bar
Instead it prints
/example/bin/example: line 233: xargs: command not found
Application was started with -Dfoo=null
Your Environment
Building with Gradle 7.3.3 on OpenJDK 17
Running in Docker on redhat/ubi8-minimal:8.5-218