maven-coordinates and dependencies

Source: Internet
Author: User

1, coordinates-find the important basis of project dependence

<groupId>cmbc.com.cn</groupId>    <artifactid>myapp</artifactid><version>1.0- Snapshot</version><packaging>war</packaging>

Description: A, groupId, Artifactid, version must be configured, packaging is optional, not configured defaults to jar

b, the project component name corresponds to the coordinates, usually artifactid-version.packaging, the above coordinate corresponding component name is called

Myapp-1.0-snapshot

2. Dependent configuration

<project>   <dependencies>  can contain multiple <dependency>    <dependency>      <groupid >...</groupId>      <artifactId>...</artifactId>      <version>...</version>      <type>...</type>    coordinate type, corresponding to the packaging      <scope>...</scope>  dependency range defined by the project coordinates      <optional>...</optional> tag dependencies are optional      <exclusions> exclude transitive dependencies        ... </exclusions>    </dependency> </dependencies></project>

3. Dependency details

    • Range of dependencies

A, the type of dependency range

b, the role of the scope of dependence

MAVEN compiles, tests, runs Classpath, and relies on a range of dependencies to control the relationship between dependencies and three kinds of classpath.

    • Transitive dependency

A, project a relies on b,b dependent on C, then C is a transitive dependency. MAVEN introduces the necessary indirect dependencies into the project in the form of transitive dependencies.

B. Determination of transitive dependency range

Project a relies on b,b for C, then B is the first direct dependence of a, C is the second direct dependence of B, and C is the transitive dependency of a. The scope of the first and second direct dependencies determines the scope of the transitive dependency, as shown below, with the first direct dependency on the left, which is the second direct dependency range, and the transitive dependency range in the middle:

    • Reliance on conciliation

When multiple direct dependencies on a project depend on the same other dependency in their own dependency path, which path should be introduced?

Rule: Different path length, shortest path priority; Same path length, first declaration preferred

    • Optional dependencies

Suppose a relies on b,b dependent on C (optional), D (optional) (Pom.xml files in Project B are dependent on C and D, <dependency> are added <optional>true</optional> in the declaration). Optional dependencies are not transitive, so C or D dependencies cannot be introduced in a project, and if you need to use C or D you need to rely directly on C or D in a project

    • Exclude dependencies

Transitive dependencies implicitly introduce many dependencies, greatly simplifying the management of project dependencies. However, you need to use <exclusions> exclude dependencies in the following situations:

A, a dependent b,b dependent C,c (snapshot version) instability may affect project a. You need to exclude C at this point and introduce a stable version of C.

b, may be due to copyright reasons, C (stable version) is not in the central warehouse, and the D project is an alternative to the implementation. You need to exclude C at this point and introduce D

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.