`AddMockitoJavaAgentToMavenSurefirePlugin` adds the agent when a parent already loads it from an explicit jar path
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- java
- 領域
- build-system
調査の方向性
Start with AddMockitoJavaAgentToMavenSurefirePlugin.java, especially the surefireArgLineWithAgent check, and trace how it handles inherited Surefire configuration and the dependency-plugin execution requirement. Add a regression test based on the parent-and-child reproduction in the issue. Done means an inherited explicit Mockito agent path prevents redundant recipe changes and preserves the parent's Surefire arguments.
索引モデルが issue の本文から書いたものです。
説明
What version of OpenRewrite are you using?
- rewrite-migrate-java 3.49.0
- rewrite-maven-plugin 6.53.0
How are you running OpenRewrite?
Through the Maven plugin, with org.openrewrite.java.migrate.UpgradeToJava25 in a multi-module project. All modules inherit from a corporate parent POM.
What is the smallest, simplest way to reproduce the problem?
The parent POM sets up the Mockito agent once for every project that inherits it. It refers to the jar by its path in the local repository, not by ${org.mockito:mockito-core:jar}:
<properties>
<argLine/>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
@{argLine}
-javaagent:${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar
</argLine>
</configuration>
</plugin>
</plugins>
</build>
A child module uses the parent and has org.mockito:mockito-core as a test dependency, with no surefire configuration of its own.
@Test
void agentInheritedFromParentAsExplicitJarPath() {
rewriteRun(
mavenProject("parent",
pomXml(/* the parent above, with mockito.version set */),
mavenProject("child",
pomXml(/* child with mockito-core test dependency, no surefire config */)
)
)
);
}
What did you expect to see?
No changes. Every module already runs its tests with the Mockito agent, inherited from the parent's build/plugins.
What did you see instead?
The recipe changes every module that uses mockito-core:
- it adds a
maven-surefire-pluginwith<argLine>-javaagent:${org.mockito:mockito-core:jar}</argLine>(or@{argLine} -javaagent:...); - it adds a
maven-dependency-pluginpropertiesexecution (get-mockito-agent-path).
The module's own <argLine> replaces the inherited one, so each module loses the rest of the parent's surefire arguments (here --add-opens and the @{argLine}/JaCoCo chaining).
Why it happens
The parent check added in #1166 (for #1164) only treats the agent as configured when the inherited argLine contains the exact text the recipe would add (AddMockitoJavaAgentToMavenSurefirePlugin.java, surefireArgLineWithAgent):
.filter(argLine -> argLine != null && argLine.contains(agentArgument))
agentArgument is -javaagent:${org.mockito:mockito-core:jar} (or the byte-buddy-agent form). It also requires an inherited maven-dependency-plugin properties execution. That execution is only needed for the ${group:artifact:jar} form.
Why a parent would use the explicit path
${org.mockito:mockito-core:jar} is only set by maven-dependency-plugin:properties in modules that depend on mockito-core. In a corporate parent that applies one surefire configuration to every project, a module without mockito-core gets an unresolved -javaagent:${org.mockito:mockito-core:jar}, and its test JVM fails to start. Referring to the jar by its path, with the version Spring Boot's BOM manages, avoids that.
Suggested fix
Treat the agent as already configured when any inherited or local surefire argLine has a -javaagent: argument that points at a Mockito or Byte Buddy agent jar, in whatever form. For example, match -javaagent:\S*(mockito-core|byte-buddy-agent)\S*, not only the exact ${...:jar} text. When that agent is not the ${...:jar} form, don't require the maven-dependency-plugin properties execution either.
Are you interested in contributing a fix to OpenRewrite?
Yes, I'm happy to open a PR with the test above and the change to surefireArgLineWithAgent.
- 主要言語
- Java
- スター
- 162
- フォーク
- 139
- 平均マージ
- 10時間 28分
- マージ済み PR(30日)
- 121
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openrewrite/rewrite-migrate-java のほかの issue
-
good first issue
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
openrewrite/rewrite-migrate-java#1330 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
UseMapOf: Skip refactoring large maps to Map.ofEntries to prevent javac compiler hangs (add maxEntries option)対応中かも @Yuren0312 が 17 日前に担当しました。 オープンbug
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
openrewrite/rewrite-migrate-java#1310 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Recipe UseMapOf generates Map.of() with nullable values or duplicate keys, causing runtime NullPointerException対応中かも @henriquejsza が 12 日前に担当しました。 オープンbug
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
openrewrite/rewrite-migrate-java#1307 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
openrewrite/rewrite-migrate-java#1246 ·
メンテナーはふだん 1 日以内に返信
-
Feedback from a 152k-line Java 8 to 25 migration: the silent behavioural changes that cost the most, and which have no recipe対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 32/100
openrewrite/rewrite-migrate-java#1227 · コメント 4 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
openrewrite/rewrite-migrate-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
aws/aws-emulator#30 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 4 日以内に返信
-
Bug: Minor Status: Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
GTNewHorizons/GT-New-Horizons-Modpack#27664 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
openrewrite/rewrite#9835 ·
メンテナーはふだん 1 日以内に返信
-
serviceability
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
OpenLiberty/open-liberty#36348 ·
メンテナーはふだん 1 日以内に返信