Preserve applicationDefaultJvmArgs in distribution start script#378
Merged
Conversation
The application-distribution plugin templated the `-javaagent` option into `CreateStartScripts.defaultJvmOpts` and then, on Unix, collapsed the individually-quoted options into a single double-quoted string so that the embedded `$APP_HOME` in the agent path would expand at assignment time. Collapsing the per-option quotes discards the boundary Gradle's native start script relies on: the launcher word-splits `$DEFAULT_JVM_OPTS`, so any option whose value contains a space (e.g. `-Dgreeting=hello world`) is split into multiple arguments -- `world` then gets treated as the main class and the app fails to start. A single space-free option like `-Dabc=123` survived by luck, which is why the existing test did not catch it. Keep every option its own quoted token. The Unix `DEFAULT_JVM_OPTS` value is still wrapped in outer double quotes (so `$APP_HOME` expands), but each option's own quotes are now backslash-escaped so they survive into the value and the launcher's `xargs` pass parses them back out intact. Multiple agents are joined with an escaped-quote separator for the same reason. Windows, which already kept literal per-option quotes, is unchanged. Adds a functional test that runs the installed distribution with a space-containing `applicationDefaultJvmArg` and asserts the value reaches the JVM as a single argument. Fixes #95 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
29c395a to
ffcb971
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #95. Applying the application-distribution plugin dropped/mangled JVM args a consumer set via
applicationDefaultJvmArgs.On Unix the plugin collapsed Gradle's individually-quoted options into a single double-quoted string (needed so
$APP_HOMEin the agent path expands). But collapsing the per-option quotes means the launcher word-splits$DEFAULT_JVM_OPTS, so any option whose value contains a space breaks:produced
DEFAULT_JVM_OPTS="-javaagent:$APP_HOME/... -Dgreeting=hello world", which the shell splits into-Dgreeting=helloandworld.worldis then treated as the main class:A space-free arg like
-Dabc=123survived by luck, which is why the existing test didn't catch it.Fix
Keep every option its own quoted token. The Unix
DEFAULT_JVM_OPTSvalue stays wrapped in outer double quotes so$APP_HOMEstill expands, but each option's own quotes are now backslash-escaped so they survive into the value and the launcher'sxargspass parses them back out intact:Multiple agents are joined with an escaped-quote separator for the same reason. Windows already kept literal per-option quotes and is unchanged.
Verification
preserves applicationDefaultJvmArgs containing spaces in application distributionruns the installed distribution and asserts the space-containing arg reaches the JVM as a single argument. It fails on the old code and passes on the fix.-Dgreeting=hello worldand-Dabc=123reach the JVM intact.🤖 Generated with Claude Code
Note
Preserve
applicationDefaultJvmArgscontaining spaces in distribution start scriptsPlatform.UNIXin Platform.kt to wrap each JVM option as an individually quoted, backslash-escaped token insideDEFAULT_JVM_OPTS, preventing shell word-splitting on options with spaces.DEFAULT_JVM_OPTSon Unix now uses the form"\"opt1\" \"opt2\""instead of a single quoted string; existing scripts that parse this value directly may see a different format.📊 Macroscope summarized ffcb971. 3 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted
🗂️ Filtered Issues
No issues evaluated.