Class Dependency

java.lang.Object
org.apache.maven.api.model.Dependency
All Implemented Interfaces:
Serializable, InputLocationTracker

The <dependency> element contains information about a dependency of the project.
See Also:
  • Method Details

    • getGroupId

      public String getGroupId()
      The project group that produced the dependency, e.g. org.apache.maven.
      Returns:
      a String
    • getArtifactId

      public String getArtifactId()
      The unique id for an artifact produced by the project group, e.g. maven-artifact.
      Returns:
      a String
    • getVersion

      public String getVersion()
      The version of the dependency, e.g. 3.2.1. In Maven 2, this can also be specified as a range of versions.
      Returns:
      a String
    • getType

      public String getType()
      The type of dependency, that will be mapped to a file extension, an optional classifier, and a few other attributes. Some examples are jar, war, ejb-client and test-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

      public 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 and javadoc: see default artifact handlers for a list,
      • distinguishing two artifacts that belong to the same POM but were built differently. For example, jdk14 and jdk15.
      Returns:
      a String
    • getScope

      public String getScope()
      The scope of the dependency - compile, runtime, test, system, and provided. 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 is compile.
      Returns:
      a String
    • getSystemPath

      public 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

      @Nonnull public List<Exclusion> 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

      public String 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 is String for technical reasons, the semantic type is actually Boolean. Default value is false.
      Returns:
      a String
    • getLocation

      public InputLocation getLocation(Object key)
      Gets the location of the specified field in the input source.
      Specified by:
      getLocation in interface InputLocationTracker
    • with

      Creates a new builder with this object as the basis.
      Returns:
      a Builder
    • withGroupId

      @Nonnull public Dependency withGroupId(String groupId)
      Creates a new Dependency instance using the specified groupId.
      Parameters:
      groupId - the new String to use
      Returns:
      a Dependency with the specified groupId
    • withArtifactId

      @Nonnull public Dependency withArtifactId(String artifactId)
      Creates a new Dependency instance using the specified artifactId.
      Parameters:
      artifactId - the new String to use
      Returns:
      a Dependency with the specified artifactId
    • withVersion

      @Nonnull public Dependency withVersion(String version)
      Creates a new Dependency instance using the specified version.
      Parameters:
      version - the new String to use
      Returns:
      a Dependency with the specified version
    • withType

      @Nonnull public Dependency withType(String type)
      Creates a new Dependency instance using the specified type.
      Parameters:
      type - the new String to use
      Returns:
      a Dependency with the specified type
    • withClassifier

      @Nonnull public Dependency withClassifier(String classifier)
      Creates a new Dependency instance using the specified classifier.
      Parameters:
      classifier - the new String to use
      Returns:
      a Dependency with the specified classifier
    • withScope

      @Nonnull public Dependency withScope(String scope)
      Creates a new Dependency instance using the specified scope.
      Parameters:
      scope - the new String to use
      Returns:
      a Dependency with the specified scope
    • withSystemPath

      @Nonnull public Dependency withSystemPath(String systemPath)
      Creates a new Dependency instance using the specified systemPath.
      Parameters:
      systemPath - the new String to use
      Returns:
      a Dependency with the specified systemPath
    • withExclusions

      @Nonnull public Dependency withExclusions(Collection<Exclusion> exclusions)
      Creates a new Dependency instance using the specified exclusions.
      Parameters:
      exclusions - the new Collection<Exclusion> to use
      Returns:
      a Dependency with the specified exclusions
    • withOptional

      @Nonnull public Dependency withOptional(String optional)
      Creates a new Dependency instance using the specified optional.
      Parameters:
      optional - the new String to use
      Returns:
      a Dependency with the specified optional
    • newInstance

      @Nonnull public static Dependency newInstance()
      Creates a new Dependency instance. Equivalent to newInstance( true ).
      Returns:
      a new Dependency
      See Also:
    • newInstance

      @Nonnull public static Dependency newInstance(boolean withDefaults)
      Creates a new Dependency instance using default values or not. Equivalent to newBuilder( withDefaults ).build().
      Parameters:
      withDefaults - the boolean indicating whether default values should be used
      Returns:
      a new Dependency
    • newBuilder

      @Nonnull public static Dependency.Builder newBuilder()
      Creates a new Dependency builder instance. Equivalent to newBuilder( true ).
      Returns:
      a new Builder
      See Also:
    • newBuilder

      @Nonnull public static Dependency.Builder newBuilder(boolean withDefaults)
      Creates a new Dependency builder instance using default values or not.
      Parameters:
      withDefaults - the boolean indicating whether default values should be used
      Returns:
      a new Builder
    • newBuilder

      @Nonnull public static Dependency.Builder newBuilder(Dependency from)
      Creates a new Dependency builder instance using the specified object as a basis. Equivalent to newBuilder( from, false ).
      Parameters:
      from - the Dependency instance to use as a basis
      Returns:
      a new Builder
    • newBuilder

      @Nonnull public static Dependency.Builder newBuilder(Dependency from, boolean forceCopy)
      Creates a new Dependency builder instance using the specified object as a basis.
      Parameters:
      from - the Dependency instance to use as a basis
      forceCopy - the boolean indicating if a copy should be forced
      Returns:
      a new Builder
    • isOptional

      public boolean isOptional()
    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • getManagementKey

      public String getManagementKey()
      Returns:
      the management key as groupId:artifactId:type