Closed ashakirin closed 1 month ago
In case if new dependency already exists, it will be doubled:
void shouldNotAddNewIfDependencyAlreadyExistsManaged() { rewriteRun( spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId( "javax.activation", "javax.activation-api", "jakarta.activation", "jakarta.activation-api", null, null )), pomXml( """ <project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version> <dependencies> <dependency> <groupId>javax.activation</groupId> <artifactId>javax.activation-api</artifactId> </dependency> <dependency> <groupId>jakarta.activation</groupId> <artifactId>jakarta.activation-api</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>javax.activation</groupId> <artifactId>javax.activation-api</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>jakarta.activation</groupId> <artifactId>jakarta.activation-api</artifactId> <version>1.2.1</version> </dependency> </dependencies> </dependencyManagement> </project> """, """ <project> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <version>1</version> <dependencies> <dependency> <groupId>jakarta.activation</groupId> <artifactId>jakarta.activation-api</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>javax.activation</groupId> <artifactId>javax.activation-api</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>jakarta.activation</groupId> <artifactId>jakarta.activation-api</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>jakarta.activation</groupId> <artifactId>jakarta.activation-api</artifactId> <version>1.2.1</version> </dependency> </dependencies> </dependencyManagement> </project> """ ) );
Of course, it is possible to add RemoveDuplicateDependencies recipe, but more clean solution is to avoid adding duplicate at all.
Moved to openrewrite
In case if new dependency already exists, it will be doubled:
Of course, it is possible to add RemoveDuplicateDependencies recipe, but more clean solution is to avoid adding duplicate at all.