"Maven Combat" notes--coordinates and dependencies

Source: Internet
Author: User

One, the scope of dependency maven when compiling the project main code, need to use a set of classpath--compiled Classpath, when compiling and executing tests, using another set of classpath--test classpath; Actually, when you run the MAVEN project, A set of classpath--is also used to run the classpath. "Scope" is used to control the dependence of the three kinds of classpath relationship, MAVEN has the following range of dependencies: 1, compile: Compiler dependency range default, for compiling, testing, running three kinds of classpath are valid, such as SPRING-CORE.2, Test: Testing the dependency range is only valid for test classpath, such as JUnit. 3. Provided: The provided dependency scope is valid for compilation and test classpath, but not valid for runtime, such as the servlet-api of the Tomcat container, compiling and testing the project needs, but when the project is run, the container is already provided. 4. Runtime: Runtime dependency range is valid for testing and running classpath, but not valid when compiling master code, such as JDBC driver implementation, Project master code only requires the JDBC interface provided by JDK, only need to implement the specific JDBC driver of the above interface when executing test or run. 5, System: Systems rely on the scope of the three kinds of classpath relationship, and provided dependency range is exactly the same, but often with the native system binding, may cause the build is not portable, so should be used with caution. 6. Import: The scope of the dependency does not have a real impact on the three types of classpath.   Second, transitive dependence, if a has a compile range of dependent b,b has a compile range of dependency C, then C will become a compile range dependence. C is a transitive dependency of a. If: A for B is the first direct dependence, B is the second direct dependence on C, and a for C is transitive dependency, then: , the left column is the first direct dependency range, the previous line is the second direct dependency, the middle is the scope of transitive dependency.   Optional Dependency    Use the optional element to represent two dependencies as optional dependencies, they only affect B, and when other projects depend on B, the two dependencies are not passed. You will need to declare the Mysql-connector-java, or PostgreSQL, in a. In the ideal case, the optional dependency should not be used!!   , excluding dependent project A depends on project B, but for some reasons, you do not want to introduce a transitive dependency C, but instead declare yourself to be a version dependent on Project C, you can use exc in your codeThe lusions element declaration excludes dependencies. Exclusions can contain one or more exclusion child elements, and exclusion only requires groupid and Artifactid. V. Classification dependency for example, the spring framework relies on different modules from the same project, all of which are the same, and if the spring framework is to be upgraded in the future, the dependent versions will be upgraded together.   Optimization of Reliance dependency:listdependency:treedependecy:analyze    



From for notes (Wiz)



"Maven Combat" notes--coordinates and 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.