spring pom scope作用
- compile,缺省值,适用于所有阶段,会随着项目一起发布。
- provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
- runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。 比如,你可能在编译的时候只需要JDBC API JAR,而只
有在运行的时候才需要JDBC驱动实现。 - test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
- system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。注意该范围是不推荐使用的
说明:当一个父pom中的dependencyManagement 标签中需要导入另一个pom中的dependencyManagement的时候,必须同时使用import 和 pom
import只能用在dependencyManagement块中,它将spring-boot-dependencies 中dependencyManagement下的dependencies插入到当前工程的dependencyManagement中,所以不存在依赖传递。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
pom.xml 中 父 pom 参考 [email protected]:D2C-Cai/herring.git