Skip to content

Add Mockito Java agent surefire config in reactor modules#1169

Merged
timtebeek merged 1 commit into
mainfrom
tim/fix-mockito-agent-surefire-reactor-1168
Jul 15, 2026
Merged

Add Mockito Java agent surefire config in reactor modules#1169
timtebeek merged 1 commit into
mainfrom
tim/fix-mockito-agent-surefire-reactor-1168

Conversation

@timtebeek

@timtebeek timtebeek commented Jul 15, 2026

Copy link
Copy Markdown
Member

Problem

In a multi-module (reactor) build where the parent pom manages maven-surefire-plugin and maven-dependency-plugin in <pluginManagement> but does not declare them in <build><plugins>, running AddMockitoJavaAgentToMavenSurefirePlugin on a child module produced a pointless partial change:

  • an empty <argLine></argLine> property was added,
  • the maven-dependency-plugin (with the properties goal) was added,
  • but the maven-surefire-plugin with 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.isAcceptable bails out when filePattern == null and the module's parent pom is part of the same reactor:

if (mrr == null || mrr.parentPomIsProjectPom()) {
    return false;
}

The surefire AddPlugin was invoked with filePattern == null, so it was silently skipped on reactor child modules. The dependency-plugin AddPlugin, however, is invoked with a **/pom.xml filePattern, which bypasses that guard — hence the inconsistent, half-applied result.

Fix

Pass the same **/pom.xml filePattern for the surefire AddPlugin so the configuration is applied consistently. The child module now gets a complete, working setup: the @{argLine} property, the dependency-plugin properties goal, 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).

…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
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jul 15, 2026
@timtebeek
timtebeek merged commit e5e1d5f into main Jul 15, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/fix-mockito-agent-surefire-reactor-1168 branch July 15, 2026 12:22
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

AddMockitoJavaAgentToMavenSurefirePlugin inserts odd empty argLine and configures dependency-plugin for no apparent reason?

1 participant