Skip to content

Conversation

@usv240
Copy link
Contributor

@usv240 usv240 commented Dec 10, 2025

Fixes #14116

Context

This PR implements support for --help, --version, and --show-version command-line arguments in the Tooling API.

Previously, providing these arguments via longRunningOperation.withArguments(...) would often fail (e.g., "Task not found" errors) or be ignored because the Tooling API treated the request as a standard build execution rather than a meta-information request.

Implementation Details:

  • Introduced VersionHelpConsumerActionExecutor to the connection chain.
  • The executor intercepts execution if --help, --version, or --show-version are detected.
  • It explicitly clears tasks and arguments to prevent build failures.
  • It queries the Help model (for --help) or BuildEnvironment model (for --version) to generate the correct output.
  • For --show-version, it prints the version information and then proceeds with the original build action.

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 :tooling-api:quickTest.

@usv240 usv240 requested review from a team as code owners December 10, 2025 00:28
@usv240 usv240 requested review from Copilot and h0tk3y December 10, 2025 00:28
@bot-gradle bot-gradle added from:contributor PR by an external contributor to-triage labels Dec 10, 2025
@usv240 usv240 force-pushed the fix/14116-tapi-cli-help branch from 1c0baeb to 69eba30 Compare December 10, 2025 00:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements support for --help, --version, and --show-version command-line arguments in the Tooling API by introducing a VersionHelpConsumerActionExecutor that intercepts these flags and handles them appropriately before build execution.

Key Changes:

  • Introduced VersionHelpConsumerActionExecutor to handle help and version flags in the Tooling API execution chain
  • Added getConnectionParameters() method to ConsumerOperationParameters for parameter access
  • Updated test preconditions from GradleBuildJvmSpecAvailable to Jdk17Available for consistency

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
platforms/ide/tooling-api/src/main/java/org/gradle/tooling/internal/consumer/connection/VersionHelpConsumerActionExecutor.java New executor that intercepts --help, --version, and --show-version arguments and handles them by querying Help or BuildEnvironment models
platforms/ide/tooling-api/src/main/java/org/gradle/tooling/internal/consumer/ConnectionFactory.java Integrates the new VersionHelpConsumerActionExecutor into the connection chain
platforms/ide/tooling-api/src/main/java/org/gradle/tooling/internal/consumer/parameters/ConsumerOperationParameters.java Adds getter method for accessing connection parameters
platforms/ide/tooling-api/src/test/groovy/org/gradle/tooling/internal/consumer/connection/VersionHelpConsumerActionExecutorTest.groovy Unit tests for the new executor covering delegation, help output, version output, and show-version scenarios
platforms/ide/tooling-api/src/crossVersionTest/groovy/org/gradle/integtests/tooling/r940/VersionHelpConsumerCrossVersionSpec.groovy Cross-version integration tests verifying behavior across Gradle versions
testing/smoke-test/src/smokeTest/groovy/org/gradle/smoketests/GradleBuildToolingApiSmokeTest.groovy Smoke tests validating the functionality in real-world scenarios
testing/smoke-test/src/smokeTest/groovy/org/gradle/smoketests/AbstractGradleceptionSmokeTest.groovy Updates test precondition and fixes path separator handling for Windows compatibility
testing/smoke-test/src/testFixtures/groovy/org/gradle/test/preconditions/SmokeTestPreconditions.groovy Adds new Jdk17Available precondition for smoke tests
testing/internal-testing/src/main/resources/valid-precondition-combinations.csv Registers the new precondition combination as valid

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cobexer cobexer removed the request for review from a team December 10, 2025 10:30
@ljacomet
Copy link
Member

Thank you for your proposed contribution!

This PR has a valid DCO and tests. The relevant team for this area will confirm the design of the implementation choices.


@usv240 Even before the team looks at this, could you make sure that ./gradlew sanityCheck passes? You can see a failure in the reported results.

@ljacomet ljacomet added in:tooling-api 👋 team-triage Issues that need to be triaged by a specific team and removed to-triage labels Dec 11, 2025
Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
@jbartok jbartok removed the 👋 team-triage Issues that need to be triaged by a specific team label Dec 16, 2025
@donat
Copy link
Member

donat commented Dec 16, 2025

@bot-gradle test ACT

@bot-gradle

This comment has been minimized.

@bot-gradle
Copy link
Collaborator


@ToolingApiVersion(">=9.4.0")
@TargetGradleVersion(">=9.4.0")
class VersionHelpConsumerCrossVersionSpec extends ToolingApiSpecification {
Copy link
Member

Choose a reason for hiding this comment

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

❌ Please separate the coverage for help and version-related coverage intoto two related test classes.

@TargetGradleVersion(">=9.4.0")
class VersionHelpConsumerCrossVersionSpec extends ToolingApiSpecification {

def "prints version info and ignores tasks when --version is present"() {
Copy link
Member

Choose a reason for hiding this comment

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

❌ Missing test coverage for old target Gradle versions.

class VersionHelpConsumerCrossVersionSpec extends ToolingApiSpecification {

def "prints version info and ignores tasks when --version is present"() {
def output = new ByteArrayOutputStream()
Copy link
Member

Choose a reason for hiding this comment

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

There's an existing result.output property available in this class. You can define assertions on that.

import java.util.Collections;
import java.util.List;

public class VersionHelpConsumerActionExecutor implements ConsumerActionExecutor {
Copy link
Member

Choose a reason for hiding this comment

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

❌ Although this kind of works, I find it quite hack-ish. I've spent quite some time and looked into the details. The main problem is that this ActionExecutor intercepts the TAPI requests at the wrong abstraction level: outside of where the project connection is available.

The main issue is that here we don't know anything about the provider side (ie the target Gradle distribution). Currently it seems sufficient that we simply catch the exception when an unsupported Gradle version is being used. At the same time, the plan is to backport the --help and the --version rendering for older Gradle versions that is impossible here.

I propose the following: move the interception logic into org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection.

  • Maybe extract the interception logic to a subclass between AbstractConsumerConnection and it's existing immediate subclass.
  • There, you have access to VersionDetails which you can use to separate the supported/unsupported cases.
  • You can do the interceptions only for task execution.
  • For model loading, launching tests you could look into how to improve existing functionality
    • Don't fail model loading/test execution when --help or --version is listed as arguments
    • Instead emit a warning that the argument list was cleaned up.

Later (in a separate PR) we can add static content for older Gradle versions in the new ConsumerConnection class.

IntegTestPreconditions$Java21HomeAvailable,IntegTestPreconditions$Java17HomeAvailable,IntegTestPreconditions$NotEmbeddedExecutor
UnitTestPreconditions$NotAlpine
UnitTestPreconditions$NotWindows,UnitTestPreconditions$NotAlpine
SmokeTestPreconditions$Jdk17Available,UnitTestPreconditions$Jdk9OrLater,IntegTestPreconditions$NotConfigCached
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Seems unrelated

].combinations()
}

def "can run with --version"() {
Copy link
Member

Choose a reason for hiding this comment

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

❌ We probably don't need this. The cross-version coverage is quite enough.


class SmokeTestPreconditions {

static class Jdk17Available implements TestPrecondition {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

@donat donat changed the title Fix/14116 tapi cli help Allow Tooling API clients to invoke --help and --version Dec 17, 2025
…nection and split tests

Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
@usv240 usv240 force-pushed the fix/14116-tapi-cli-help branch from e4b3487 to 83a7631 Compare December 17, 2025 22:51
@usv240
Copy link
Contributor Author

usv240 commented Dec 18, 2025

Hi @donat ,
Thanks for the review. I’ve addressed the requested changes and updated the implementation and tests accordingly. Please let me know if anything else needs adjustment.

@donat donat self-requested a review December 23, 2025 08:18
Copy link
Member

@donat donat left a comment

Choose a reason for hiding this comment

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

I'm confused now. The last commit on this PR removed the behavior that we expect:

If the user runs the build with --help or --version the tasks should be ignored and the corresponding help or version info should be printed on the console.

Please restore that behavior.

- Added handleHelpOrVersion() to intercept flags for task execution
- Removed flags with warning for model/test operations
- Implemented help precedence over version flags
- Fixed entry point requirement in model parameter builder
- Updated tests with correct expectations and precedence coverage

Addresses review feedback from @donat.
Fixes gradle#14116

Signed-off-by: Ujwal Suresh Vanjare <[email protected]>
@usv240
Copy link
Contributor Author

usv240 commented Dec 24, 2025

Hi @donat
Sorry about the confusion! My previous commit was incomplete - I only removed the arguments without actually handling them.

Fixed now with the complete implementation. All your feedback has been addressed.

@usv240 usv240 requested a review from donat December 24, 2025 03:01
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:tooling-api

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to use --version --help command line arguments via TAPI

5 participants