Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of Maven dependency scope, transmission, and exclusion?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the "Maven dependence scope, transmission, exclusion method is what", in the daily operation, I believe that many people in the Maven dependence scope, transmission, exclusion method is what the problem is, the editor consulted all kinds of data, sorted out a simple and useful method of operation, hope to answer the "Maven dependence scope, transmission, exclusion method is what" the doubt is helpful! Next, please follow the editor to study!

Add dependency

Next I add a spring-web dependency, and maven will download spring-web 's jar package and some of the jar packages it depends on.

Org.springframework

Spring-web

4.2.5.RELEASE

Compile

Dependent range

There is a scope in the dependency configuration that has not been mentioned before, which is the dependency scope. What is the dependency scope is to specify at which stage your jar package is valid.

Compile-compilation dependency scope. The default scope, which can be left unfilled, means that it is valid for all processes, such as compilation, testing, run, and so on.

Provided-dependency scope has been provided. This scope means that only the compile and test phases are available and are not needed at run time, such as the servlet-api already provided by containers such as tomcat.

Runtime-Runtime dependency scope. This range means that it is valid only during run and test, and is not needed during compilation, such as the jdbc driver that connects to the database.

Test-Test the scope of dependency. This scope is valid only during the test phase and is not required to compile and run, like the junit package provided by unit tests.

System-system dependency scope. This scope means that it does not depend on the local repository. Jar is in other directories and needs to specify a path through systemPath, which is not recommended.

Import-reference dependency scope. The scope added after Maven2.0.9 can only be used in, and the imported type is a parent project configuration of pom type, which is generally used to solve the problem of multi-inheritance.

Dependency transfer

Dependency transfer mentioned earlier can be achieved through inheritance and aggregation, can be easily inherited from the parent project through inheritance, and can be passed indirectly through aggregation.

Inheritance: an inherits B's dependencies dependency if it inherits BMaga.

Aggregation: a depends on C and C depends on D, so A depends on D and naturally acquires D's dependence.

Below is a list of direct and all indirect dependencies for dubbo.

Dependency exclusion

In the process of dependency transmission, for example, A depends on B, S2.0 and B depend on C and S1.0, so A has two dependencies of S1.0 and S2.0, which will cause conflicts in some cases. It is necessary to manually eliminate the dependency passed by B indirectly, that is, it does not rely on the package of S1.0 brought by B.

Org.testgroupId >

B

1.0

Com.test

S

Eliminate all indirect dependencies

Org.testgroupId >

B

1.0

*

*

At this point, the study of "what is the scope of Maven dependence, transmission and exclusion" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report