Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`AddLombokMapstructBinding` adds redundant dependency when `lombok-mapstruct-binding` is already configured in `maven-compiler-plugin` `annotationProcessorPaths`

未关闭
#1,319 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
build-system

调研方向

Start by reading rewrite-migrate-java/src/main/resources/META-INF/rewrite/java-version-17.yml and the AddLombokMapstructBindingMavenDependencyOnly recipe it invokes. Trace how it checks Maven dependencies and how AddAnnotationProcessor handles maven-compiler-plugin annotation processor paths. Done means running the recipe leaves the POM unchanged when lombok-mapstruct-binding is already configured in annotationProcessorPaths, while still adding it when needed.

由索引模型根据 Issue 内容生成。

描述

bug

What version of OpenRewrite are you using?

I am using

  • rewrite-maven-plugin: 6.50.0
  • release: 8.93.0

How are you running OpenRewrite?

I am using the Maven plugin on a multi-module Maven project:

mvn org.openrewrite.maven:rewrite-maven-plugin:6.49.0:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:3.46.0 -Drewrite.activeRecipes=org.openrewrite.java.migrate.UpgradeToJava17

What is the smallest, simplest way to reproduce the problem?

Create a Maven POM that uses both Lombok and MapStruct, and has lombok-mapstruct-binding properly configured inside maven-compiler-plugin <annotationProcessorPaths>:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>example-service</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.36</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.mapstruct</groupId>
      <artifactId>mapstruct</artifactId>
      <version>1.6.3</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.13.0</version>
        <configuration>
          <annotationProcessorPaths>
            <path>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok</artifactId>
              <version>1.18.36</version>
            </path>
            <path>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok-mapstruct-binding</artifactId>
              <version>0.2.0</version>
            </path>
            <path>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-processor</artifactId>
              <version>1.6.3</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Run recipe org.openrewrite.java.migrate.AddLombokMapstructBinding (or org.openrewrite.java.migrate.UpgradeToJava17 / UpgradeToJava21).

What did you expect to see?

No changes to pom.xml. lombok-mapstruct-binding is already configured in <annotationProcessorPaths> of maven-compiler-plugin. Per Lombok and MapStruct documentation, it belongs in javac's annotation processor classpath, not as a project compile/runtime dependency in <dependencies>.

What did you see instead?

The recipe blindly injects lombok-mapstruct-binding as a compile-scope project dependency into <dependencies>:

   <dependencies>
+    <dependency>
+      <groupId>org.projectlombok</groupId>
+      <artifactId>lombok-mapstruct-binding</artifactId>
+      <version>0.2.0</version>
+    </dependency>
     <dependency>
       <groupId>org.projectlombok</groupId>
       <artifactId>lombok</artifactId>
Root Cause

In rewrite-migrate-java/src/main/resources/META-INF/rewrite/java-version-17.yml:

name: org.openrewrite.java.migrate.AddLombokMapstructBinding
recipeList:
  - org.openrewrite.gradle.AddDependency: ...
  - org.openrewrite.java.migrate.AddLombokMapstructBindingMavenDependencyOnly
  - org.openrewrite.maven.AddAnnotationProcessor:
      groupId: org.projectlombok
      artifactId: lombok-mapstruct-binding
      version: 0.2.0
  - org.openrewrite.java.migrate.AddMapstructAnnotationProcessorPath

AddLombokMapstructBinding calls AddLombokMapstructBindingMavenDependencyOnly, which only checks if lombok-mapstruct-binding is present under <dependencies> (DoesNotIncludeDependency). It does not check whether lombok-mapstruct-binding is already configured in maven-compiler-plugin <annotationProcessorPaths>. Consequently, projects that already use modern <annotationProcessorPaths> get a redundant compile dependency injected into <dependencies>.

主要语言
Java
星标
160
派生
133
平均合并
7 小时 49 分钟
30 天内合并 PR
60

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openrewrite/rewrite-migrate-java 的其他 Issue

查看 openrewrite/rewrite-migrate-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。