编程知识 cdmana.com

Maven dependency range

An example

With servlet Of maven Take dependency as an example

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>
 Copy code 

there scope That's what he depends on ,maven It will automatically determine whether to import the... According to the timing jar package

scope Parameters

Depend on the range Compilation works The test works It works Example
compile Y Y Y spring-core
test - Y - Junit
provided Y Y - servlet-api
runtime - Y Y JDBC drive
system Y Y - The local ,Maven Class libraries outside the warehouse
  • compile compile 、 test 、 function , Depend on... At compile time , And it also depends on
    for example : strus-core、spring-beans. Call war Package or jar package
  • provided compile 、 And tests are effective , When compiling and testing, you need
    for example : servlet-api Is that compilation and testing are useful , Don't use... At run time (tomcat The container has been provided ) It won't hit war
  • runtime: test 、 It works
    for example : jdbc Drive pack , In the development code for java Of jdbc Interface development , Compilation does not need to pass... When running and testing jdbc Drive pack (mysq drive ) Connect to database , I'll call you if I need it war
  • test: It's just that the test works , Use... Only in unit test classes
    for example : junit
    It won't hit war

According to the dependent intensity , Sort from strong to weak :( understand )

compile>provided> runtime> test

版权声明
本文为[kehao98]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/07/20210729160003359d.html

Scroll to Top