Scope usage in Maven

Original address: https://www.cnblogs.com/asingna/p/5234908.html

Dependency Scope 

In POM 4, <dependency> also introduces <scope>, which mainly manages the deployment of dependencies. Currently <scope> can use 5 values: 

    * compile, the default value, applicable to all stages, will be released with the project. 
    * provided, similar to compile, expects JDK, container or user to provide this dependency. Such as servlet.jar. 
    * runtime, only used at runtime, such as JDBC driver, suitable for running and testing phases. 
    * test, used only when testing, for compiling and running test code. Not released with the project. 
    *system, like provided, needs to explicitly provide the jar containing the dependencies, Maven will not look it up in the Repository.

Dependency scope controls which dependencies are available on which classpath and which dependencies are included in an application. Let's look at each scope in detail:
 
compile (compile scope)
 
compile is the default scope; if no scope is provided, the dependency's scope is the compile scope. compile-scope dependencies are available on all classpaths,

At the same time they will also be packaged.
 
provided (scope provided) A
 
provided dependency is used only after the dependency has been provided by the JDK or a container. For example, if you develop a web application, you may be compiling

The Servlet API needs to be available on the classpath to compile a servlet, but you don't want to include the Servlet API in the packaged WAR; this

The Servlet API JAR is provided by your application server or servlet container. Provided scoped dependencies are available on the compile classpath (not runtime). they

Not transitive and not packaged.
 
runtime (runtime scope)
 
runtime dependencies are required when running and testing the system, but not when compiling. For example, you might only need the JDBC API JAR at compile time, and only

A JDBC
 driver implementation is only required at runtime.
 
test (test scope)
 
test scope dependencies are not needed at normal compile and run time, they are only available during the test compile and test run phases.
 
system (system-wide)
 
system-wide dependencies are similar to provided, but you must explicitly provide a path to the JAR file on the local system. This is done to allow local-based

Objects are compiled, and these objects are part of the system class library. Such an artifact should always be available and Maven will not look for it in the repository. if you put a

To set the dependency scope to system scope, you must also provide a systemPath element. Note that this scope is deprecated (you should always try to remove from public or

referenced dependencies in a custom Maven repository).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325595616&siteId=291194637