Scope details in Maven dependencies

Source: Internet
Author: User
Tags pack

One of Maven's philosophies is that the Convention is better than configuration (Convention over config), and the default value of scope is compile in the MAVEN default dependency configuration item, and the project is often innocently confused and directly default. Comb Maven's scope today. Classification of Scope Compile

The default is compile, and nothing is configured to mean compile. Compile indicates that the dependent project needs to be involved in the compilation of the current project, and of course the subsequent testing and operation Cycles are also involved, a relatively strong dependency. It usually needs to be included in the package. Test

Scope for test indicates that dependent projects are only involved in testing-related work, including the compilation and execution of test code. More typical, such as JUnit. Runntime

Runntime indicates that a dependent project does not need to be involved in the compilation of the project, but later testing and running cycles require its participation. Compared to compile, skip compiling , to be honest in the terminal project (non-open source, enterprise internal system), and compile difference is not very big. More common, such as the implementation of JSRXXX, the corresponding API jar is compile, the implementation is runtime, compile just need to know the interface is enough. The Oracle JDBC driver package is a good example of a general scope of Runntime. In addition, the dependency of runntime is usually used in conjunction with optional, optional is true. I can use a to achieve, can also be implemented with B. provided

Provided means that you can pack it without having to pack it in, and other facilities (Web Container) will provide. In fact, the dependency theory can be involved in compiling, testing, running and other cycles. The equivalent of compile, but in the packaging phase did a exclude action. system

In terms of engagement, the same is provided, but the dependencies are not captured from the Maven repository, but are taken from the local file system and must be used with the Systempath attribute . dependency delivery of scope

A–>b–>c. The current project for A,a relies on b,b dependent on C. Knowing the scope of B in Project A, how do you know the scope of C in a? The answer is:
When C is test or provided, C is discarded directly, a does not depend on C;
Otherwise a dependent c,c scope inherits from the scope of B.

Below is a picture of a nexus picture.
Friendship Link

Calligraphy and Chinese painting enthusiasts come in

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.