Only add the Mockito surefire agent configuration when asked, and keep it minimal - #1184
Merged
Merged
Conversation
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.
Summary
AddMockitoJavaAgentToMavenSurefirePluginonly adds surefire's@{argLine}late replacement (and the emptyargLineproperty that backs it) when something actually supplies that propertyUpgradePluginsForJava25, soUpgradeToJava25does not add the Mockito agent configuration on its ownProblem
org.mockito:mockito-corepicked up amaven-dependency-pluginpropertiesexecution, an empty<argLine/>property, and a surefire<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>as a side effect of migrating to Java 25. That is a sizeable, hard-to-unwind diff across a large estate, and it is not something the migration strictly requires: Mockito's Byte Buddy self-attachment still works on current JDKs, JEP 451 only warns about it.Solution
Only use
@{argLine}when it buys something. Surefire's late replacement exists so that a value another plugin sets at build time (in practice JaCoCo'sprepare-agent) survives into the test JVM, and it drags along an emptyargLineproperty so builds without such a provider do not pass the literal token to the JVM. Both are now added only when anargLineproperty is already declared or JaCoCo is present. Poms with neither get:Output is unchanged when JaCoCo or an existing
argLineis in play.Two details worth calling out:
RawPom.Profiledoes not parse<build><plugins>, so a JaCoCo declaration that is only active under a profile never reachesResolvedPom.getPlugins(); going through the resolved model would silently drop coverage for those projects. Scanning the document also picks uppluginManagement. JaCoCo inherited from a parent pom's profile remains undetectable.<argLine/>previously fell back to the literal string@{argLine}. Left as-is that would now emit@{argLine}with no property backing it, so a blank value is treated as if the tag were absent.Make the recipe opt-in. Removed from
UpgradePluginsForJava25. The description now explains that self-attachment still works today and that the recipe is about silencing the JDK warning and staying ahead of the eventual restriction, since users have to seek it out deliberately now.The trade-off: teams migrating to Java 25 no longer get this hardening automatically and will keep seeing the dynamic-agent-loading warning. Happy to reconsider and keep it bundled with only the first change if that balance seems wrong.
Test plan
Existing tests pass (
./gradlew build)New tests added: no runtime
argLineprovider, JaCoCo inbuild/plugins, JaCoCo only under a profile, and anargLineproperty already declaredUpgradeToJava25Testasserts the agent configuration is no longer addedrecipes.csvregenerated andexamples.ymlupdated for the new@DocumentExampleoutputFixes moderneinc/customer-requests#2942