Scope explained in Maven Pom.xml

Source: Internet
Author: User

One, compile: compilation scope
Compile is the default scope, and if a scope is not provided, the compilation scope dependency is available in all classpath, and they are also packaged. And these dependency will be passed on to the dependent projects.

Second, provided: has provided the scope
Provided dependency is provided by a JDK or container. For example, if you develop a Web application, you might need the servlet APIs available in the compilation Classpath to compile a servlet, but you don't want to include this servlet API in a packaged war, the Servlet API JAR 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.
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>

III. 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, a JDBC API JAR may be required at compile time, and only the JDBC driver implementation is required when running.

Iv. test: Scope of 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.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

V. System: Scope of systems
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).

Scope explained in Maven Pom.xml

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.