dependency:add
Full name:
org.apache.maven.plugins:maven-dependency-plugin:3.11.0:add
Description:
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.
Attributes:
- Requires a Maven project to be executed.
- The goal is thread-safe and supports parallel builds.
- Since version:
3.11.0.
Optional Parameters
| Name | Type | Since | Description |
|---|---|---|---|
<align> |
boolean |
3.11.0 |
When true (the default), automatically detect and follow the project's existing dependency management conventions:
managed, useProperty, propertyName) override detected conventions.Default: trueUser Property: align |
<classifier> |
String |
3.11.0 |
Dependency classifier (e.g., sources, javadoc, tests).User Property: classifier |
<gav> |
String |
3.11.0 |
Dependency coordinates: groupId:artifactId[:version] or groupId:artifactId[:extension[:classifier]]:version. Scope, type, classifier, and optional can be overridden via separate parameters.User Property: gav |
<managed> |
boolean |
3.11.0 |
When true, insert into <dependencyManagement> instead of <dependencies>.Default: falseUser Property: managed |
<optional> |
Boolean |
3.11.0 |
Whether the dependency is optional. User Property: optional |
<profile> |
String |
3.11.0 |
Target a specific Maven profile by its <id>. When set, the dependency is added to the profile's <dependencies> or <dependencyManagement> section. The profile must already exist in the POM.User Property: profile |
<propertyName> |
String |
3.11.0 |
Explicit property name for the version (e.g., guava.version). When not set, the name is derived from the detected naming convention.User Property: propertyName |
<scope> |
String |
3.11.0 |
Dependency scope. Validated against Maven's known scope values: compile, provided, runtime, test, system, import. Invalid values are rejected with a org.apache.maven.plugin.MojoFailureException.User Property: scope |
<silent> |
boolean |
2.0 |
Deprecated. to be removed in 4.0; use -q command line option instead If the plugin should be silent. Default: falseUser Property: silent |
<skip> |
boolean |
2.7 |
Skip plugin execution completely. Default: falseUser Property: mdep.skip |
<skipDuringIncrementalBuild> |
boolean |
3.4.0 |
Skip plugin execution only during incremental builds (e.g. triggered from M2E). See also: org.apache.maven.plugins.dependency.AbstractDependencyMojo.skip Default: false |
<type> |
String |
3.11.0 |
Dependency type/packaging (e.g., jar, pom, war).User Property: type |
<useProperty> |
Boolean |
3.11.0 |
When set, controls whether a version property is created in <properties>. When null (the default), the behavior is auto-detected from existing conventions if align=true.User Property: useProperty |
Parameter Details
<align>
true (the default), automatically detect and follow the project's existing dependency management conventions:
- If most existing dependencies are version-less, add managed dependency to parent POM
- If versions use
${...} property references, create a version property - Property naming follows the detected pattern (e.g.,
.version,-version)
managed, useProperty, propertyName) override detected conventions.- Type:
boolean - Since:
3.11.0 - Required:
No - User Property:
align - Default:
true
<classifier>
sources, javadoc, tests).- Type:
java.lang.String - Since:
3.11.0 - Required:
No - User Property:
classifier
<gav>
groupId:artifactId[:version] or groupId:artifactId[:extension[:classifier]]:version. Scope, type, classifier, and optional can be overridden via separate parameters.- Type:
java.lang.String - Since:
3.11.0 - Required:
No - User Property:
gav
<managed>
true, insert into <dependencyManagement> instead of <dependencies>.- Type:
boolean - Since:
3.11.0 - Required:
No - User Property:
managed - Default:
false
<optional>
- Type:
java.lang.Boolean - Since:
3.11.0 - Required:
No - User Property:
optional
<profile>
<id>. When set, the dependency is added to the profile's <dependencies> or <dependencyManagement> section. The profile must already exist in the POM.- Type:
java.lang.String - Since:
3.11.0 - Required:
No - User Property:
profile
<propertyName>
guava.version). When not set, the name is derived from the detected naming convention.- Type:
java.lang.String - Since:
3.11.0 - Required:
No - User Property:
propertyName
<scope>
compile, provided, runtime, test, system, import. Invalid values are rejected with a org.apache.maven.plugin.MojoFailureException.- Type:
java.lang.String - Since:
3.11.0 - Required:
No - User Property:
scope
<silent>
to be removed in 4.0; use -q command line option instead
- Type:
boolean - Since:
2.0 - Required:
No - User Property:
silent - Default:
false
<skip>
- Type:
boolean - Since:
2.7 - Required:
No - User Property:
mdep.skip - Default:
false
<skipDuringIncrementalBuild>
See also: org.apache.maven.plugins.dependency.AbstractDependencyMojo.skip
- Type:
boolean - Since:
3.4.0 - Required:
No - Default:
false
<type>
jar, pom, war).- Type:
java.lang.String - Since:
3.11.0 - Required:
No - User Property:
type
<useProperty>
<properties>. When null (the default), the behavior is auto-detected from existing conventions if align=true.- Type:
java.lang.Boolean - Since:
3.11.0 - Required:
No - User Property:
useProperty

