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
mergify Bot
added a commit
to robfrank/linklift
that referenced
this pull request
Aug 4, 2026
…40.0 to 3.41.0 [skip ci] Bumps [org.openrewrite.recipe:rewrite-migrate-java](https://github.com/openrewrite/rewrite-migrate-java) from 3.40.0 to 3.41.0. Release notes *Sourced from [org.openrewrite.recipe:rewrite-migrate-java's releases](https://github.com/openrewrite/rewrite-migrate-java/releases).* > 3.41.0 > ------ > > What's Changed > -------------- > > * Add Mockito Java agent surefire config in reactor modules by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#1169](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1169) > * Move Java EE 8 servlet update into separate recipe by [`@rlsanders4`](https://github.com/rlsanders4) in [openrewrite/rewrite-migrate-java#1170](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1170) > * Update NoGuavaRefaster expected output for upstream static-import change by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#1171](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1171) > * Set Develocity `projectId` to "openrewrite" by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#1172](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1172) > * Add `mapstruct-processor` to annotation processor paths when Lombok and MapStruct are used by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#1175](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1175) > * Fix method patterns for dead `UnsignedInts`/`UnsignedLongs` recipes by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-migrate-java#1176](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1176) > * Migrate web.xml xsi:schemaLocation from J2EE 1.4 namespace by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-migrate-java#1177](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1177) > * Forward Code Genome Project publish credentials to `ci-gradle.yml` by [`@jkschneider`](https://github.com/jkschneider) in [openrewrite/rewrite-migrate-java#1178](https://redirect.github.com/openrewrite/rewrite-migrate-java/pull/1178) > > **Full Changelog**: <openrewrite/rewrite-migrate-java@v3.40.0...v3.41.0> Commits * [`128764a`](openrewrite/rewrite-migrate-java@128764a) Forward Code Genome Project publish credentials to `ci-gradle.yml` ([#1178](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/1178)) * [`39b31e8`](openrewrite/rewrite-migrate-java@39b31e8) Migrate web.xml xsi:schemaLocation from J2EE 1.4 namespace ([#1177](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/1177)) * [`e7f0b34`](openrewrite/rewrite-migrate-java@e7f0b34) [Auto] SDKMAN! Java candidates as of 2026-07-27T1252 * [`e29c330`](openrewrite/rewrite-migrate-java@e29c330) Fix method patterns for dead `UnsignedInts`/`UnsignedLongs` recipes ([#1176](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/1176)) * [`7c45df7`](openrewrite/rewrite-migrate-java@7c45df7) Add `mapstruct-processor` to annotation processor paths when Lombok and MapSt... * [`ab370a9`](openrewrite/rewrite-migrate-java@ab370a9) Set Develocity `projectId` to "openrewrite" ([#1172](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/1172)) * [`cddded8`](openrewrite/rewrite-migrate-java@cddded8) Move Develocity to community.develocity.cloud * [`577446f`](openrewrite/rewrite-migrate-java@577446f) Update NoGuavaRefaster expected output for upstream static-import change ([#1171](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/1171)) * [`9b7a874`](openrewrite/rewrite-migrate-java@9b7a874) [Auto] SDKMAN! Java candidates as of 2026-07-20T1212 * [`a5b7ddc`](openrewrite/rewrite-migrate-java@a5b7ddc) Move Java EE 8 servlet update into separate recipe ([#1170](https://redirect.github.com/openrewrite/rewrite-migrate-java/issues/1170)) * Additional commits viewable in [compare view](openrewrite/rewrite-migrate-java@v3.40.0...v3.41.0)
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).