Skip to content

Commit c4adf19

Browse files
Wrapping the adding of the dependency for org.projectlombok:lombok-mapstruct-binding in a check to make sure you do not already have said dependency (potentially in another scope)
1 parent c47788e commit c4adf19

File tree

2 files changed

+225
-4
lines changed

2 files changed

+225
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,25 @@ recipeList:
327327
version: 0.2.0
328328
configuration: annotationProcessor
329329
acceptTransitive: false
330-
- org.openrewrite.maven.AddDependency:
330+
- org.openrewrite.java.migrate.AddLombokMapstructBindingMavenDependencyOnly
331+
- org.openrewrite.maven.AddAnnotationProcessor:
331332
groupId: org.projectlombok
332333
artifactId: lombok-mapstruct-binding
333334
version: 0.2.0
334-
acceptTransitive: false
335-
- org.openrewrite.maven.AddAnnotationProcessor:
335+
---
336+
type: specs.openrewrite.org/v1beta/recipe
337+
name: org.openrewrite.java.migrate.AddLombokMapstructBindingMavenDependencyOnly
338+
displayName: Add `lombok-mapstruct-binding` dependency for Maven when both MapStruct and Lombok are used
339+
description: >-
340+
Add the `lombok-mapstruct-binding` when both MapStruct and Lombok are used, and the dependency does not already exist.
341+
Only to be called from `org.openrewrite.java.migrate.AddLombokMapstructBinding` to reduce redundant checks
342+
preconditions:
343+
- org.openrewrite.java.dependencies.search.DoesNotIncludeDependency:
344+
groupId: org.projectlombok
345+
artifactId: lombok-mapstruct-binding
346+
recipeList:
347+
- org.openrewrite.maven.AddDependency:
336348
groupId: org.projectlombok
337349
artifactId: lombok-mapstruct-binding
338350
version: 0.2.0
339-
351+
acceptTransitive: false

src/test/java/org/openrewrite/java/migrate/UpgradeToJava17Test.java

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,4 +611,213 @@ void upgradeMapstructAndAnnotationPathsWithGradle() {
611611
)
612612
);
613613
}
614+
615+
@Test
616+
void addsLombokMapstructBindingIfBothLombokAndMapstruct() {
617+
rewriteRun(
618+
spec -> spec.beforeRecipe(withToolingApi()),
619+
mavenProject("project",
620+
//language=groovy
621+
buildGradle(
622+
"""
623+
plugins { id 'java' }
624+
repositories { mavenCentral() }
625+
dependencies {
626+
implementation "org.projectlombok:lombok:1.18.42"
627+
implementation "org.mapstruct:mapstruct:1.6.3"
628+
}
629+
""",
630+
"""
631+
plugins { id 'java' }
632+
repositories { mavenCentral() }
633+
dependencies {
634+
annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0"
635+
636+
implementation "org.projectlombok:lombok:1.18.42"
637+
implementation "org.mapstruct:mapstruct:1.6.3"
638+
}
639+
"""
640+
),
641+
//language=xml
642+
pomXml(
643+
"""
644+
<project>
645+
<groupId>com.mycompany.app</groupId>
646+
<artifactId>my-app</artifactId>
647+
<version>1</version>
648+
<properties>
649+
<maven.compiler.release>11</maven.compiler.release>
650+
</properties>
651+
<dependencies>
652+
<dependency>
653+
<groupId>org.projectlombok</groupId>
654+
<artifactId>lombok</artifactId>
655+
<version>1.18.42</version>
656+
</dependency>
657+
<dependency>
658+
<groupId>org.mapstruct</groupId>
659+
<artifactId>mapstruct</artifactId>
660+
<version>1.6.3</version>
661+
</dependency>
662+
</dependencies>
663+
<plugins>
664+
<plugin>
665+
<groupId>org.apache.maven.plugins</groupId>
666+
<artifactId>maven-compiler-plugin</artifactId>
667+
<configuration>
668+
<annotationProcessorPaths>
669+
<path>
670+
<groupId>org.projectlombok</groupId>
671+
<artifactId>lombok</artifactId>
672+
</path>
673+
</annotationProcessorPaths>
674+
</configuration>
675+
<version>3.14.1</version>
676+
</plugin>
677+
</plugins>
678+
</project>
679+
""",
680+
"""
681+
<project>
682+
<groupId>com.mycompany.app</groupId>
683+
<artifactId>my-app</artifactId>
684+
<version>1</version>
685+
<properties>
686+
<maven.compiler.release>17</maven.compiler.release>
687+
</properties>
688+
<dependencies>
689+
<dependency>
690+
<groupId>org.projectlombok</groupId>
691+
<artifactId>lombok</artifactId>
692+
<version>1.18.42</version>
693+
</dependency>
694+
<dependency>
695+
<groupId>org.projectlombok</groupId>
696+
<artifactId>lombok-mapstruct-binding</artifactId>
697+
<version>0.2.0</version>
698+
</dependency>
699+
<dependency>
700+
<groupId>org.mapstruct</groupId>
701+
<artifactId>mapstruct</artifactId>
702+
<version>1.6.3</version>
703+
</dependency>
704+
</dependencies>
705+
<plugins>
706+
<plugin>
707+
<groupId>org.apache.maven.plugins</groupId>
708+
<artifactId>maven-compiler-plugin</artifactId>
709+
<configuration>
710+
<annotationProcessorPaths>
711+
<path>
712+
<groupId>org.projectlombok</groupId>
713+
<artifactId>lombok</artifactId>
714+
</path>
715+
<path>
716+
<groupId>org.projectlombok</groupId>
717+
<artifactId>lombok-mapstruct-binding</artifactId>
718+
<version>0.2.0</version>
719+
</path>
720+
</annotationProcessorPaths>
721+
</configuration>
722+
<version>3.14.1</version>
723+
</plugin>
724+
</plugins>
725+
</project>
726+
"""
727+
),
728+
mavenProject("anotherProject",
729+
//language=xml
730+
pomXml(
731+
"""
732+
<project>
733+
<groupId>org.someother</groupId>
734+
<artifactId>anotherproject</artifactId>
735+
<version>1.0.0</version>
736+
<properties>
737+
<maven.compiler.release>17</maven.compiler.release>
738+
</properties>
739+
<dependencies>
740+
</dependencies>
741+
</project>
742+
"""
743+
)
744+
)
745+
)
746+
);
747+
}
748+
749+
@Test
750+
void doesNotDuplicateLombokMapstructBinding() {
751+
rewriteRun(
752+
spec -> spec.beforeRecipe(withToolingApi()),
753+
mavenProject("project",
754+
//language=groovy
755+
buildGradle(
756+
"""
757+
plugins { id 'java' }
758+
repositories { mavenCentral() }
759+
dependencies {
760+
annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0"
761+
762+
implementation "org.projectlombok:lombok:1.18.42"
763+
implementation "org.mapstruct:mapstruct:1.6.3"
764+
}
765+
"""
766+
),
767+
//language=xml
768+
pomXml(
769+
"""
770+
<project>
771+
<groupId>com.mycompany.app</groupId>
772+
<artifactId>my-app</artifactId>
773+
<version>1</version>
774+
<properties>
775+
<maven.compiler.release>17</maven.compiler.release>
776+
<lombok.mapstruct.binding.version>0.2.0</lombok.mapstruct.binding.version>
777+
</properties>
778+
<dependencies>
779+
<dependency>
780+
<groupId>org.projectlombok</groupId>
781+
<artifactId>lombok</artifactId>
782+
<version>1.18.42</version>
783+
<scope>provided</scope>
784+
</dependency>
785+
<dependency>
786+
<groupId>org.projectlombok</groupId>
787+
<artifactId>lombok-mapstruct-binding</artifactId>
788+
<version>${lombok.mapstruct.binding.version}</version>
789+
<scope>provided</scope>
790+
</dependency>
791+
<dependency>
792+
<groupId>org.mapstruct</groupId>
793+
<artifactId>mapstruct</artifactId>
794+
<version>1.6.3</version>
795+
</dependency>
796+
</dependencies>
797+
<plugins>
798+
<plugin>
799+
<groupId>org.apache.maven.plugins</groupId>
800+
<artifactId>maven-compiler-plugin</artifactId>
801+
<configuration>
802+
<annotationProcessorPaths>
803+
<path>
804+
<groupId>org.projectlombok</groupId>
805+
<artifactId>lombok</artifactId>
806+
</path>
807+
<path>
808+
<groupId>org.projectlombok</groupId>
809+
<artifactId>lombok-mapstruct-binding</artifactId>
810+
<version>0.2.0</version>
811+
</path>
812+
</annotationProcessorPaths>
813+
</configuration>
814+
<version>3.14.1</version>
815+
</plugin>
816+
</plugins>
817+
</project>
818+
"""
819+
)
820+
)
821+
);
822+
}
614823
}

0 commit comments

Comments
 (0)