Basic explanation of scope tags in pom files

Classification of scopes

Reference: https://www.cnblogs.com/nanyangzp/p/4813228.html

 

1. compile: The compile scope
compile is the default scope; if no scope is provided, the compile scope dependencies are available on all classpaths , and they will also be packaged. And these dependencies will be passed to the dependent projects.

 

 

 

2. Provided: The scope
provided is provided. It is clear that the dependency is provided by the JDK or the container. For example, if you develop a web application, you may need the Servlet API available on the compile classpath to compile a servlet, but you would not want to include the Servlet API in the packaged WAR; the Servlet API JAR is provided by your application server or Provided by the servlet container. Provided scoped dependencies are available on the compile classpath (not 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>

 

 

 

Third, runtime: runtime scope
runtime dependencies are required when running and testing the system, but not when compiling. For example, you may only need the JDBC API JAR at compile time, and only need the JDBC driver implementation at runtime.

 

 

 

Fourth, test: test scope
test scope dependencies are not needed in general compilation and runtime, they are only available in the test compilation and test runtime phases.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

 

 

 

5. 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 native objects that 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 set a dependency scope to be system scope, you must also provide a systemPath element. Note that this scope is deprecated (you should always try to reference dependencies from public or custom Maven repositories).

 

 

Guess you like

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