Class DuplicateElementStrategy

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

@Named @Singleton @Priority(21) public class DuplicateElementStrategy extends AbstractUpgradeStrategy
Strategy for removing duplicate XML elements in POM files.

Maven 4's stricter POM parser rejects duplicate XML elements (such as <artifactId>, <properties>, <version>, etc.) that Maven 3 silently accepted using last-wins semantics. This strategy scans each POM element's children and removes duplicates, keeping only the last occurrence of each element name.

This strategy only targets "scalar" elements at well-known POM schema positions — elements that should appear at most once within their parent according to the Maven POM schema. Elements inside list containers (e.g., <dependency> inside <dependencies>, <plugin> inside <plugins>) are not affected by this strategy since duplicate dependencies and plugins are handled by DeduplicateDependenciesStrategy.

Plugin <configuration> elements are skipped entirely, because they contain free-form, plugin-specific XML whose schema is not known to this tool. Treating same-named children as duplicates in configuration sections (e.g., multiple <arg> entries inside <compilerArgs>) would silently remove valid list entries and break builds.

See Also:
  • Constructor Details

    • DuplicateElementStrategy

      public DuplicateElementStrategy()
  • 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