Maven dependency, maven

Source: Internet
Author: User

Maven dependency, maven

Optional dependencies:

1. Which version is called? The shortest dependency Length

For example, if A-> B-> C-> D 2.0, A-> E-> D 1.0, call D 1.0.

To avoid this situation, you can directly define A-> D 2.0, that is, the dependency explicitly defined by yourself is always called first, regardless of the version level.

2. if the version is not declared? The latest version is used by default.

3. exclude A dependency, such as A-> B-> C. A can explicitly exclude the dependency on C.

<dependency>      <groupId>group-a</groupId>      <artifactId>artifact-a</artifactId>      <version>1.0</version>      <exclusions>        <exclusion>          <groupId>group-c</groupId>          <artifactId>excluded-artifact</artifactId>        </exclusion>      </exclusions>    </dependency>

4. Optional dependencies, such as B-> C, but are declared as optional. C is no longer dependent on A-> B, which is equivalent to being excluded by default.

Of course, you can also explicitly add dependencies on C. The two are irrelevant.

 

5. scope:

  • Compile(Default, saving)
  • Provided, Which will be provided by JDK or WebServer, such as Servlet API, required during compilation,Not passed
  • Runtime, Used for running, not required during compilation,Not passed
  • Test, Used for testing,Not passed
  • System, Indicates that this is provided explicitly, and you do not need to find it in the code base. This is required during compilation,Not passed
  • ImportUsed only<DependencyManagement>And does not affect the transfer.
<Dependencies> <dependency> <groupId> sun. jdk </groupId> <artifactId> tools </artifactId> <version> 1.5.0 </version> <scope> system </scope> <systemPath >$ {java. home }/.. /lib/tools. jar </systemPath> Self-specified </dependency> </dependencies>

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.