Class RemoveDependencyMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.dependency.AbstractDependencyMojo
org.apache.maven.plugins.dependency.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 Details

    • gav

      @Parameter(property="gav") private 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 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 String classifier
      Dependency classifier for precise matching (e.g., sources, javadoc, tests).
      Since:
      3.11.0
    • profile

      @Parameter(property="profile") private 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 Details

    • RemoveDependencyMojo

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

    • 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, File pomFile) throws org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoFailureException
    • loadPomEditor

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

      private static void savePomEditor(eu.maveniverse.domtrip.maven.PomEditor editor, File pomFile) throws IOException
      Throws:
      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, String depGroupId, String depArtifactId) throws org.apache.maven.plugin.MojoExecutionException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
    • resolveModulePom

      private static File resolveModulePom(File parentBasedir, String moduleName)