Fixes #847.
Fixes #743.
What changed
This PR avoids wiring native-image agent instrumentation into Gradle Java execution tasks when the resolved agent mode is disabled.
Before this change, Gradle run and other JavaExec-style tasks could still pick up agent-related wiring even when the build was not actually running with the tracing agent. That could interfere with repeated executions and task up-to-date behavior.
After this change, agent wiring is only applied when the resolved agent mode is enabled, while real agent runs still keep their existing output tracking.
Why
This prevents disabled-agent builds from paying the cost or behavioral side effects of instrumentation wiring, while preserving the expected behavior for builds that do enable the tracing agent.
Example
Before:
Running a Gradle run task, or an IntelliJ-style JavaExec task, multiple times without -Pagent could still be affected by agent instrumentation wiring even though the agent was disabled.
After:
The same tasks run without agent wiring when -Pagent is not enabled, while builds that do enable the agent still keep the expected tracing-agent behavior and output tracking.
Implementation summary
- Skip agent task wiring when the resolved agent mode is disabled.
- Keep agent output tracking in place for executions that actually run with the agent enabled.
- Add regression coverage for repeated Gradle
run and IntelliJ-style JavaExec executions without -Pagent.
- Keep existing agent-enabled
run and configuration-cache coverage in place to verify the enabled path still behaves correctly.
Validation
JAVA_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal ./gradlew :native-gradle-plugin:functionalTest --tests 'org.graalvm.buildtools.gradle.JavaApplicationFunctionalTest.does not make JavaExec tasks up-to-date when the agent is disabled'
JAVA_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal GRAALVM_HOME=/home/jovan/.sdkman/candidates/java/25.0.2-graal ./gradlew :native-gradle-plugin:functionalTest --tests 'org.graalvm.buildtools.gradle.JavaApplicationWithAgentFunctionalTest.agent instruments run task'
JAVA_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal GRAALVM_HOME=/home/jovan/.sdkman/candidates/java/25.0.2-graal ./gradlew :native-gradle-plugin:functionalTest --tests 'org.graalvm.buildtools.gradle.JavaApplicationWithAgentFunctionalTest.supports configuration cache'
JAVA_HOME=/home/jovan/.sdkman/candidates/java/17.0.12-graal ./gradlew :native-gradle-plugin:checkstyleMain