[Switch] Detailed scope of Maven

In the POM 4, <dependency> also introduced <scope>, which is mainly dependent on the management of the deployment. Currently <scope> You can use five values: 

* the compile, the default values for all stages, will be released along with the project. 
* Provided, similar to compile, expectations JDK, container, or the user may provide this dependency. As servlet.jar. 
* Runtime, only at runtime, such as JDBC driver for running and testing phase. 
* Test, the test is only used when, for compiling and running the test code. It will not be published with the project. 
* System, similar to the provided, required to provide explicit dependence comprising jar, Maven does not find it in the Repository.

Which relies range control which in dependence classpath available, which is included in an application-dependent. Let's look at the details of each range:

the compile  (compile range)

compile is the default range; if not provided a range, that range is dependent on the scope of the compilation. Compiling range depends on all available in the classpath, while they will be packaged.

Provided  (scope has been provided)

provided only dependent JDK or when used after a container has been provided to the dependency. For example, if you develop a web application, you may need to compile available in the classpath Servlet API to compile a servlet, but you do not want to include the Servlet API in the packaged WAR; the Servlet API JAR of your application server or servlet container available. It has provided a range of dependence can be used in compiling classpath (not runtime). They are not transitive, it will not be packaged.

Runtime  (running range)

runtime dependent on when to run and test system needs, but is not required at compile time. For example, you may only need JDBC API JAR at compile time, but only when it needs to run the JDBC
driver implementation.

Test  (test range)

test range in general depend on the compilation and runtime are not needed, they can be used only in test compilation and test operation phase.

System  (system-wide)

range depends similar system provided, but you must explicitly provide a path for the local system JAR file. This is done to allow the compiler based on local objects, and these objects are part of the system library. This component should be always available, Maven will not go looking for it in the warehouse. If you depend on a range set to system-wide, you must provide a systemPath element. Note that this range is not recommended (you should always try to rely on references from public or custom Maven repository).

 

Reference article: https://www.cnblogs.com/hzzll/p/6738955.html

Guess you like

Origin www.cnblogs.com/atai/p/10966276.html