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
-
Field Summary
Fields inherited from class AbstractDependencyMojo
sessionFields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
ConstructorsConstructorDescriptionAddDependencyMojo(org.apache.maven.execution.MavenSession session, org.sonatype.plexus.build.incremental.BuildContext buildContext, org.apache.maven.project.MavenProject project) -
Method Summary
Methods inherited from class AbstractDependencyMojo
execute, existsInResolvedModel, getProject, isSilent, isSkip, setSilent, setSkipMethods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
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:
doExecutein classAbstractDependencyMojo- Throws:
org.apache.maven.plugin.MojoExecutionException-MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException-MojoFailureException
-