Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,319 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
build-system

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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>.

Ngôn ngữ chính
Java
Star
159
Fork
130
Merge trung bình
7 giờ 49 phút
Pull request đã merge (30 ngày)
60

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openrewrite/rewrite-migrate-java

Tất cả issue của openrewrite/rewrite-migrate-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.