Maven scope Attribute Value Setting meaning

Source: Internet
Author: User

1. enumerate the meaning of each attribute value

    • Compile, default value. It applies to all stages and is packaged into the project.
    • Provided, similar to compile, expects JDK, container, or user to provide this dependency.
    • Runtime, used only at runtime, such as the JDBC driver, applicable to the running and testing stages.
    • Test, which is only used for testing and is used to compile and run the test code. Will not be released along with the project.
    • System, similar to provided, must explicitly provide jar containing dependencies, MAVEN will not find it in repository.

2. attribute values of other types are easy to understand. Here we will compare the differences between compile and runtime:

(1) describe a simple example: module A depends on X, and the scope value of X is runtime;

(2) If another Module B depends on a, B will not depend on X during compilation (there will be no problems during compilation );

If the scope of X is set to compile, it indicates that at the time of compilation, B needs to display the class related to calling X. JDBC is the most common setting of Maven dependency as the dependency of runtime, the main reason is that the configuration of the driver class in JDBC uses the reflection mechanism to configure class-name in the configuration file;

 

Maven scope Attribute Value Setting meaning

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.