Skip to content

Use args file instead of classpath shortening#34227

Merged
big-guy merged 8 commits into
gradle:masterfrom
koppor:use-argsfile
Mar 18, 2026
Merged

Use args file instead of classpath shortening#34227
big-guy merged 8 commits into
gradle:masterfrom
koppor:use-argsfile

Conversation

@koppor

@koppor koppor commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Fixes #34003

(Duplicate issue #34226)

Context

./gradlew :jabgui:run does not work at two persons of our team.

Contributor Checklist

  • Review Contribution Guidelines.
  • Make sure that all commits are signed off to indicate that you agree to the terms of Developer Certificate of Origin.
  • Make sure all contributed code can be distributed under the terms of the Apache License 2.0, e.g. the code was written by yourself or the original code is licensed under a license compatible to Apache License 2.0.
  • Check "Allow edit from maintainers" option in pull request so that additional changes can be pushed by Gradle team.
  • Provide integration tests (under <subproject>/src/integTest) to verify changes from a user perspective.
  • Provide unit tests (under <subproject>/src/test) to verify logic.
  • Update User Guide, DSL Reference, and Javadoc for public-facing changes.
  • Ensure that tests pass sanity check: ./gradlew sanityCheck.
  • Ensure that tests pass locally: ./gradlew <changed-subproject>:quickTest.

Reviewing cheatsheet

Before merging the PR, comments starting with

  • ❌ ❓must be fixed
  • 🤔 💅 should be fixed
  • 💭 may be fixed
  • 🎉 celebrate happy things

@bot-gradle bot-gradle added from:contributor PR by an external contributor to-triage labels Jul 11, 2025
@koppor

koppor commented Jul 12, 2025

Copy link
Copy Markdown
Contributor Author

Tests should go into org.gradle.process.internal.JavaExecHandleBuilderTest, because org.gradle.process.internal.JavaExecHandleBuilder overrides build().

Did not see another test for hasCommandLineExceedMaxLength, therefore, I did not add another test.

@ljacomet

Copy link
Copy Markdown
Member

Thank you for your proposed contribution!

This PR has a valid DCO. The relevant team for this area will confirm the design of the implementation choices and follow up on what tests should be added or changed.

@ljacomet ljacomet added in:modular-java in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures 👋 team-triage Issues that need to be triaged by a specific team and removed to-triage labels Jul 14, 2025
@big-guy big-guy removed the 👋 team-triage Issues that need to be triaged by a specific team label Jul 22, 2025
@big-guy big-guy added this to the 9.x milestone Jul 22, 2025
@big-guy

big-guy commented Jul 22, 2025

Copy link
Copy Markdown
Member

This is a good idea, but we need to continue to support the pathing jar on Java 8. We should be able to use an argfile for all Java 9+.

We won't get to this for 9.1. If you're willing to make more changes, let us know.

@koppor

koppor commented Jul 23, 2025

Copy link
Copy Markdown
Contributor Author

This is a good idea, but we need to continue to support the pathing jar on Java 8. We should be able to use an argfile for all Java 9+.

In case javaModuleDetector == null is the riight check for Java 8 in the context of org.gradle.process.internal.JavaExecHandleBuilder, I refactored the solution to keep "the old way" for Java 8:;

image

@koppor

koppor commented Jul 24, 2025

Copy link
Copy Markdown
Contributor Author

If I do "Update branch" on GitHub, the DCO test fails. Should I ignore that - or should I use the command line to keep this branch recent?

I am assuming, it will be at least 2026 until this is re-considered, but I am planning to check back weekly (at least monthly) and keep the branch recent to avoid effort for integrating.

@koppor

koppor commented Aug 4, 2025

Copy link
Copy Markdown
Contributor Author

If you're willing to make more changes, let us know.

Yes, I am willing to make more changes. I pushed updates two weeks ago adressing Java 8 compatibiltiy.

@koppor

koppor commented Sep 29, 2025

Copy link
Copy Markdown
Contributor Author

With today's version of the patch (w/ latest master included; d2b825f), we can build a distribution.

@big-guy big-guy self-assigned this Nov 3, 2025
@big-guy big-guy removed this from the 9.3.0 RC1 milestone Nov 10, 2025
@big-guy big-guy added this to the 9.5.0 RC1 milestone Jan 20, 2026
@Siedlerchr

Copy link
Copy Markdown

Any chance of getting this in the next Gradle version? This is really annoying

koppor and others added 7 commits March 18, 2026 00:59
Signed-off-by: Oliver Kopp <kopp.dev@gmail.com>
Signed-off-by: Oliver Kopp <kopp.dev@gmail.com>
Signed-off-by: Oliver Kopp <kopp.dev@gmail.com>
Signed-off-by: Oliver Kopp <kopp.dev@gmail.com>
Signed-off-by: Oliver Kopp <kopp.dev@gmail.com>
Signed-off-by: Oliver Kopp <kopp.dev@gmail.com>
@big-guy big-guy requested review from a team as code owners March 18, 2026 05:41
@big-guy big-guy requested review from alllex, asodja and big-guy and removed request for a team March 18, 2026 05:41
@big-guy big-guy added this pull request to the merge queue Mar 18, 2026

@big-guy big-guy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience. This should be in 9.5

return shortenedArguments;
} catch (IOException e) {
LOGGER.info("Pathing JAR could not be created, Gradle cannot shorten the command line.", e);
if (javaModuleDetector == null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this looked suspicious and I realize now what's going on...

This can only be null in some very specific situations, which wouldn't be encountered with a JavaExec task or someone using javaexec {}.

For regular use, this is always non-null, so this doesn't detect whether or not the underlying Java executable will support arg files or not. We end up using arg files no matter what.

I added an integ test that fails when running with Java 8 + shortening: https://ge.gradle.org/s/dpuamnzel2m5o/tests/task/:language-java:embeddedIntegTest/details/org.gradle.api.tasks.JavaExecWithLongCommandLineIntegrationTest/succeeds%20with%20long%20command%20line%20using%20Java%208%20toolchain?top-execution=1

I looked around how we could do this properly. We have a JvmMetadataDetector service which would tell us the version of Java by probing the JVM, but there appear to be a couple of problems with that:

  • We might be using JavaExecHandleBuilder itself to probe
  • We're dealing with the executable as just a String
  • There are a lot of hoops to get this service down here

But I found a way around this, which is to see that we have --module or --module-path and assume we can use arg files (because only Java 9+ supports those args).

That does mean that you can do something strange:

  • Have a project that's producing a module
  • Configure a JavaExec to use Java 8

Gradle would detect that to run the project, we need to use module-path and that would fail once we start Java 8. It would be nicer if Gradle realized the configured JVM was incompatible before even trying to start it. But that's a problem for another day.

@alllex alllex removed their request for review March 18, 2026 07:49
Merged via the queue into gradle:master with commit 2e298b1 Mar 18, 2026
17 checks passed
@koppor

koppor commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your patience. This should be in 9.5

Thank you so much for the follow-up! I was also struggling with JVM detection and "guessed" some approach. Nice workaround with --module! 🥂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:contributor PR by an external contributor in:java-plugins java-library, java, java-base, java-platform, java-test-fixtures in:modular-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: long path mitigation for JavaExec places everything in classpath

7 participants