The role of scope in the Maven dependency relationship

Source: Internet
Author: User

Currently <scope> can use 5 values:

(1) compile (compilation)
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.

(2) provided (provided)
Similar to compile, expect that the JDK, container, or user will provide this dependency. such as Servlet.jar. 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 compiling classpath to compile a servlet, but you don't want to include the Servlet API in the packaged war;

This servlet API JAR is provided by your 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.

(3) Runtime (runtime)
Used only at runtime, runtime relies on the need to run and test the system, but is not required at compile time. For example, you might only need the JDBC API JAR when compiling, and only the JDBC driver implementation is required when running.

(4) test (when testing)
Test range dependencies are not required for general compilation and runtime, and they are available only during the test compilation and test run phases.

(5) System (systems)
A jar,maven that contains dependencies needs to be explicitly provided does not look for it in repository.

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).

The role of scope in the Maven dependency relationship

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.