Add Mockito Java agent surefire config in reactor modules#1169
Merged
Conversation
…tor modules When a module's parent pom is part of the same reactor and manages the surefire and dependency plugins in pluginManagement (without declaring them in build/plugins), the recipe added an empty argLine property and the maven-dependency-plugin, but skipped adding the surefire plugin with the Java agent argLine. AddPlugin with a null filePattern refuses to run on modules whose parent is a project pom, so the surefire configuration was silently dropped while the dependency-plugin (which passes a **/pom.xml filePattern) was added, leaving a pointless partial change. Pass the same **/pom.xml filePattern for the surefire AddPlugin so the configuration is added consistently, producing a complete, working setup. Fixes #1168
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
In a multi-module (reactor) build where the parent pom manages
maven-surefire-pluginandmaven-dependency-pluginin<pluginManagement>but does not declare them in<build><plugins>, runningAddMockitoJavaAgentToMavenSurefirePluginon a child module produced a pointless partial change:<argLine></argLine>property was added,maven-dependency-plugin(with thepropertiesgoal) was added,maven-surefire-pluginwith the actual-javaagent:...argLine was never added.This is exactly what the reporter saw: an "odd empty argLine and dependency-plugin for no apparent reason", with nothing that actually wires up the Mockito agent.
Root cause
AddPluginVisitor.isAcceptablebails out whenfilePattern == nulland the module's parent pom is part of the same reactor:The surefire
AddPluginwas invoked withfilePattern == null, so it was silently skipped on reactor child modules. The dependency-pluginAddPlugin, however, is invoked with a**/pom.xmlfilePattern, which bypasses that guard — hence the inconsistent, half-applied result.Fix
Pass the same
**/pom.xmlfilePattern for the surefireAddPluginso the configuration is applied consistently. The child module now gets a complete, working setup: the@{argLine}property, the dependency-pluginpropertiesgoal, and the surefire plugin with the Java agent argLine that references them.Added a test reproducing the reporter's structure (parent manages both plugins in
pluginManagement, child only declares the Mockito test dependency).