Class RemoveDependencyMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="remove",
          requiresProject=true,
          threadSafe=true)
    public class RemoveDependencyMojo
    extends AbstractDependencyMojo
    Removes a dependency from the project's pom.xml. Supports removing from <dependencies> or <dependencyManagement>.

    Matching uses groupId, artifactId, type, and classifier for precision. If the dependency exists in Maven's resolved model but uses property references in the raw POM, a clear error directs the user to edit manually.

    When removing a managed dependency from a parent POM, warns if child modules reference it without an explicit version.
    Since:
    3.11.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String classifier
      Dependency classifier for precise matching (e.g., sources, javadoc, tests).
      private java.lang.String gav
      Dependency coordinates: groupId:artifactId[:version] or groupId:artifactId[:extension[:classifier]]:version.
      private boolean managed
      When true, remove from <dependencyManagement> instead of <dependencies>.
      private java.lang.String profile
      Target a specific Maven profile by its <id>.
      private java.lang.String type
      Dependency type for precise matching (e.g., pom, war, test-jar).
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      RemoveDependencyMojo​(org.apache.maven.execution.MavenSession session, org.sonatype.plexus.build.incremental.BuildContext buildContext, org.apache.maven.project.MavenProject project)  
    • Field Detail

      • gav

        @Parameter(property="gav")
        private java.lang.String gav
        Dependency coordinates: groupId:artifactId[:version] or groupId:artifactId[:extension[:classifier]]:version. Only groupId and artifactId are required. Type and classifier, if provided, are used for precise matching when multiple dependency variants exist (e.g., jar vs test-jar).
        Since:
        3.11.0
      • managed

        @Parameter(property="managed",
                   defaultValue="false")
        private boolean managed
        When true, remove from <dependencyManagement> instead of <dependencies>.
        Since:
        3.11.0
      • type

        @Parameter(property="type")
        private java.lang.String type
        Dependency type for precise matching (e.g., pom, war, test-jar). When not specified, defaults to "jar".
        Since:
        3.11.0
      • classifier

        @Parameter(property="classifier")
        private java.lang.String classifier
        Dependency classifier for precise matching (e.g., sources, javadoc, tests).
        Since:
        3.11.0
      • profile

        @Parameter(property="profile")
        private java.lang.String profile
        Target a specific Maven profile by its <id>. When set, the dependency is removed from the profile's <dependencies> or <dependencyManagement> section. The profile must already exist in the POM.
        Since:
        3.11.0
    • Constructor Detail

      • RemoveDependencyMojo

        @Inject
        public RemoveDependencyMojo​(org.apache.maven.execution.MavenSession session,
                                    org.sonatype.plexus.build.incremental.BuildContext buildContext,
                                    org.apache.maven.project.MavenProject project)
    • Method Detail

      • doExecute

        protected void doExecute()
                          throws org.apache.maven.plugin.MojoExecutionException,
                                 org.apache.maven.plugin.MojoFailureException
        Specified by:
        doExecute in class AbstractDependencyMojo
        Throws:
        org.apache.maven.plugin.MojoExecutionException - MojoExecutionException
        org.apache.maven.plugin.MojoFailureException - MojoFailureException
      • dependenciesFor

        private eu.maveniverse.domtrip.maven.PomEditor.Dependencies dependenciesFor​(eu.maveniverse.domtrip.maven.PomEditor editor,
                                                                                    java.io.File pomFile)
                                                                             throws org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoFailureException
      • loadPomEditor

        private static eu.maveniverse.domtrip.maven.PomEditor loadPomEditor​(java.io.File pomFile)
                                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • savePomEditor

        private static void savePomEditor​(eu.maveniverse.domtrip.maven.PomEditor editor,
                                          java.io.File pomFile)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • resolveCoordinates

        private DependencyEntry resolveCoordinates()
                                            throws org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoFailureException
      • checkChildModuleDependencies

        private void checkChildModuleDependencies​(org.apache.maven.project.MavenProject parentProject,
                                                  java.lang.String depGroupId,
                                                  java.lang.String depArtifactId)
                                           throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • resolveModulePom

        private static java.io.File resolveModulePom​(java.io.File parentBasedir,
                                                     java.lang.String moduleName)