Class AddDependencyMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.dependency.AbstractDependencyMojo
org.apache.maven.plugins.dependency.AddDependencyMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="add", requiresProject=true, threadSafe=true) public class AddDependencyMojo extends AbstractDependencyMojo
Adds a dependency to the project's pom.xml. Supports adding to <dependencies> or <dependencyManagement>, with version inference from managed dependencies.

If the dependency already exists, the goal fails with a descriptive error directing the user to remove it first.

The goal uses formatting-preserving DOM manipulation to maintain the POM's existing structure (comments, indentation, encoding). Duplicate detection uses type and classifier-aware matching, and cross-references Maven's resolved model to catch dependencies declared via property references.

Scope values are validated against Maven's known scopes: compile, provided, runtime, test, system, import.

Since:
3.11.0
  • Constructor Details

    • AddDependencyMojo

      @Inject public AddDependencyMojo(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