Package org.apache.maven.api.model
Class Dependency
java.lang.Object
org.apache.maven.api.model.Dependency
- All Implemented Interfaces:
Serializable
,InputLocationTracker
@Experimental
@Generated
@ThreadSafe
@Immutable
public class Dependency
extends Object
implements Serializable, InputLocationTracker
The
<dependency>
element contains information about a dependency
of the project.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder class used to create Dependency instances. -
Constructor Summary
ModifierConstructorDescriptionprotected
Dependency
(Dependency.Builder builder) Constructor for this class, to be called from its subclasses andDependency.Builder
. -
Method Summary
Modifier and TypeMethodDescriptionThe unique id for an artifact produced by the project group, e.g.The classifier of the dependency.Lists a set of artifacts that should be excluded from this dependency's artifact list when it comes to calculating transitive dependencies.The project group that produced the dependency, e.g.Gets the input location that caused this model to be read.getLocation
(Object key) Gets the location of the specified field in the input source.Gets the keys of the locations of the input source.Indicates the dependency is optional for use of this library.getScope()
The scope of the dependency -compile
,runtime
,test
,system
, andprovided
.FOR SYSTEM SCOPE ONLY.getType()
The type of dependency, that will be mapped to a file extension, an optional classifier, and a few other attributes.The version of the dependency, e.g.boolean
static Dependency.Builder
Creates a newDependency
builder instance.static Dependency.Builder
newBuilder
(boolean withDefaults) Creates a newDependency
builder instance using default values or not.static Dependency.Builder
newBuilder
(Dependency from) Creates a newDependency
builder instance using the specified object as a basis.static Dependency.Builder
newBuilder
(Dependency from, boolean forceCopy) Creates a newDependency
builder instance using the specified object as a basis.static Dependency
Creates a newDependency
instance.static Dependency
newInstance
(boolean withDefaults) Creates a newDependency
instance using default values or not.toString()
with()
Creates a new builder with this object as the basis.withArtifactId
(String artifactId) Creates a newDependency
instance using the specified artifactId.withClassifier
(String classifier) Creates a newDependency
instance using the specified classifier.withExclusions
(Collection<Exclusion> exclusions) Creates a newDependency
instance using the specified exclusions.withGroupId
(String groupId) Creates a newDependency
instance using the specified groupId.withOptional
(String optional) Creates a newDependency
instance using the specified optional.Creates a newDependency
instance using the specified scope.withSystemPath
(String systemPath) Creates a newDependency
instance using the specified systemPath.Creates a newDependency
instance using the specified type.withVersion
(String version) Creates a newDependency
instance using the specified version.
-
Constructor Details
-
Dependency
Constructor for this class, to be called from its subclasses andDependency.Builder
.- See Also:
-
-
Method Details
-
getGroupId
The project group that produced the dependency, e.g.org.apache.maven
.- Returns:
- a
String
-
getArtifactId
The unique id for an artifact produced by the project group, e.g.maven-artifact
.- Returns:
- a
String
-
getVersion
The version of the dependency, e.g.3.2.1
. Since Maven 2, this can also be specified as a range of versions.- Returns:
- a
String
-
getType
The type of dependency, that will be mapped to a file extension, an optional classifier, and a few other attributes. Some examples arejar
,war
,ejb-client
andtest-jar
: see default artifact handlers for a list. New types can be defined by extensions, so this is not a complete list.- Returns:
- a
String
-
getClassifier
The classifier of the dependency. It is appended to the filename after the version. This allows:- referring to attached artifact, for example
sources
andjavadoc
: see default artifact handlers for a list, - distinguishing two artifacts
that belong to the same POM but were built differently.
For example,
jdk14
andjdk15
.
- Returns:
- a
String
- referring to attached artifact, for example
-
getScope
The scope of the dependency -compile
,runtime
,test
,system
, andprovided
. Used to calculate the various classpaths used for compilation, testing, and so on. It also assists in determining which artifacts to include in a distribution of this project. For more information, see the dependency mechanism. The default scope iscompile
.- Returns:
- a
String
-
getSystemPath
FOR SYSTEM SCOPE ONLY. Note that use of this property is discouraged and may be replaced in later versions. This specifies the path on the filesystem for this dependency. Requires an absolute path for the value, not relative. Use a property that gives the machine specific absolute path, e.g.${java.home}
.- Returns:
- a
String
-
getExclusions
Lists a set of artifacts that should be excluded from this dependency's artifact list when it comes to calculating transitive dependencies.- Returns:
- a
List<Exclusion>
-
getOptional
Indicates the dependency is optional for use of this library. While the version of the dependency will be taken into account for dependency calculation if the library is used elsewhere, it will not be passed on transitively. Note: While the type of this field isString
for technical reasons, the semantic type is actuallyBoolean
. Default value isfalse
.- Returns:
- a
String
-
getLocation
Gets the location of the specified field in the input source.- Specified by:
getLocation
in interfaceInputLocationTracker
-
getLocationKeys
Gets the keys of the locations of the input source. -
getLocationKeyStream
-
getImportedFrom
Gets the input location that caused this model to be read.- Specified by:
getImportedFrom
in interfaceInputLocationTracker
- Returns:
- InputLocation
-
with
Creates a new builder with this object as the basis.- Returns:
- a
Builder
-
withGroupId
Creates a newDependency
instance using the specified groupId.- Parameters:
groupId
- the newString
to use- Returns:
- a
Dependency
with the specified groupId
-
withArtifactId
Creates a newDependency
instance using the specified artifactId.- Parameters:
artifactId
- the newString
to use- Returns:
- a
Dependency
with the specified artifactId
-
withVersion
Creates a newDependency
instance using the specified version.- Parameters:
version
- the newString
to use- Returns:
- a
Dependency
with the specified version
-
withType
Creates a newDependency
instance using the specified type.- Parameters:
type
- the newString
to use- Returns:
- a
Dependency
with the specified type
-
withClassifier
Creates a newDependency
instance using the specified classifier.- Parameters:
classifier
- the newString
to use- Returns:
- a
Dependency
with the specified classifier
-
withScope
Creates a newDependency
instance using the specified scope.- Parameters:
scope
- the newString
to use- Returns:
- a
Dependency
with the specified scope
-
withSystemPath
Creates a newDependency
instance using the specified systemPath.- Parameters:
systemPath
- the newString
to use- Returns:
- a
Dependency
with the specified systemPath
-
withExclusions
Creates a newDependency
instance using the specified exclusions.- Parameters:
exclusions
- the newCollection<Exclusion>
to use- Returns:
- a
Dependency
with the specified exclusions
-
withOptional
Creates a newDependency
instance using the specified optional.- Parameters:
optional
- the newString
to use- Returns:
- a
Dependency
with the specified optional
-
newInstance
Creates a newDependency
instance. Equivalent tonewInstance(true)
.- Returns:
- a new
Dependency
- See Also:
-
newInstance
Creates a newDependency
instance using default values or not. Equivalent tonewBuilder(withDefaults).build()
.- Parameters:
withDefaults
- the boolean indicating whether default values should be used- Returns:
- a new
Dependency
-
newBuilder
Creates a newDependency
builder instance. Equivalent tonewBuilder(true)
.- Returns:
- a new
Builder
- See Also:
-
newBuilder
Creates a newDependency
builder instance using default values or not.- Parameters:
withDefaults
- the boolean indicating whether default values should be used- Returns:
- a new
Builder
-
newBuilder
Creates a newDependency
builder instance using the specified object as a basis. Equivalent tonewBuilder(from, false)
.- Parameters:
from
- theDependency
instance to use as a basis- Returns:
- a new
Builder
-
newBuilder
Creates a newDependency
builder instance using the specified object as a basis.- Parameters:
from
- theDependency
instance to use as a basisforceCopy
- the boolean indicating if a copy should be forced- Returns:
- a new
Builder
-
isOptional
public boolean isOptional() -
toString
-
getManagementKey
- Returns:
- the management key as
groupId:artifactId:type
-