Remove duplicate Maven dependencies

Apache 2.0

Maven 3.10 and Maven 4 fail the build when a <dependencies> or <dependencyManagement> section, including those of a profile, declares the same groupId:artifactId:type:classifier more than once, regardless of <scope>. Earlier Maven versions only warned and used the last declaration. A project's own <dependencyManagement> was the exception when no parent or active profile managed dependencies too. There, duplicate BOM imports used the first one. Without any BOM import, child modules and projects importing it as a BOM used the first declaration, and the project itself took each field from the first declaration that set it. This recipe removes the duplicates in the position of the first, keeping the declaration earlier Maven versions used so that the resolved dependencies stay the same. Without any BOM import, it keeps the first declaration of a pom project and merges the declarations of any other project.

org.openrewrite.maven.RemoveDuplicateDependencies
mod run . --recipe=org.openrewrite.maven.RemoveDuplicateDependencies

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.