Class DeduplicateDependenciesStrategy

java.lang.Object
org.apache.maven.cling.invoker.mvnup.goals.AbstractUpgradeStrategy
org.apache.maven.cling.invoker.mvnup.goals.DeduplicateDependenciesStrategy
All Implemented Interfaces:
UpgradeStrategy

@Named @Singleton @Priority(19) public class DeduplicateDependenciesStrategy extends AbstractUpgradeStrategy
Strategy for deduplicating dependency and plugin declarations in POM files.

Maven 4 rejects duplicate <dependency> entries (same groupId, artifactId, type, and classifier) that Maven 3 silently accepted. This strategy scans each POM's <dependencies> and <dependencyManagement>/<dependencies> sections and removes duplicates using last-wins semantics (keeping the last declaration). Note that Maven 3's dependency resolver uses first-wins for same-depth conflicts; last-wins is chosen here intentionally so the most recently added (and presumably most up-to-date) declaration is preserved.

The strategy also handles duplicate <plugin> entries in <plugins> and <pluginManagement>/<plugins> sections with the same last-wins semantics (which does match Maven 3's plugin configuration merging behavior).

Profile-scoped dependency and plugin sections are processed as well.

  • Constructor Details

    • DeduplicateDependenciesStrategy

      public DeduplicateDependenciesStrategy()
  • Method Details

    • isApplicable

      public boolean isApplicable(UpgradeContext context)
      Description copied from interface: UpgradeStrategy
      Checks if this strategy is applicable given the current options.
      Parameters:
      context - the upgrade context
      Returns:
      true if this strategy should be applied
    • getDescription

      public String getDescription()
      Description copied from interface: UpgradeStrategy
      Gets a description of what this strategy does.
      Returns:
      a human-readable description of the strategy
    • doApply

      protected UpgradeResult doApply(UpgradeContext context, Map<Path, eu.maveniverse.domtrip.Document> pomMap)
      Description copied from class: AbstractUpgradeStrategy
      Subclasses implement the actual upgrade logic here.
      Specified by:
      doApply in class AbstractUpgradeStrategy
      Parameters:
      context - the upgrade context
      pomMap - map of all POM files in the project
      Returns:
      the result of the upgrade operation