Dependency scope value meaning in Maven pom

Source: Internet
Author: User

Quoted http://my.oschina.net/boonya/blog/141276

<scope> is also introduced in the,<dependency> in Pom 4, which primarily manages dependent deployments. Currently <scope> can use 5 values:

* Compile, default, applies to all stages and will be published along with the project.
* provided, similar to compile, expects the JDK, container or user to provide this dependency. such as Servlet.jar.
* Runtime, used only at runtime, such as JDBC driver, for run and test phases.
* Test, used only during testing, to compile and run the test code. Will not be published with the project.
* System, similar to provided, needs to explicitly provide an jar,maven that contains dependencies and does not find it in repository.

Dependencies control which dependencies are available in which classpath, and which dependencies are included in an application. Let's take a look at each of these ranges in detail:

Compile (compilation scope)

Compile is the default scope, and if a scope is not provided, the scope of the dependency is the compilation scope. Compilation scope dependencies are available in all classpath, and they are also packaged.

provided (range provided)

Provided dependencies are only used when the JDK or a container has provided the dependency. For example, if you develop a Web application, you might need the Servlet API available in the compilation Classpath to compile a servlet, but you don't want to include the Servlet API in the packaged war, and this servlet API JAR is made by your Provided by the application server or the servlet container. A dependency that has been provided for scope is available at compile classpath (not at runtime). They are not transitive and will not be packaged.

Runtime (run-time range)

Runtime relies on the need to run and test the system, but it is not required at compile time. For example, you might need only the JDBC API JAR when compiling, but only if you need JDBC at runtime
Drive implementation.

Test (Test Range)

Test range dependencies are not required for general compilation and runtime, and they are available only during the test compilation 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 in the local system. This is done to allow compilation based on local objects, which are part of the System class library. Such artifacts should always be available, and Maven will not look for it in the warehouse. If you set a dependency scope to a system scope, you must provide a SYSTEMPATH element at the same time. Note that this range is deprecated (you should always try to reference dependencies from a public or custom Maven repository).

Dependency scope value meaning in Maven pom

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.