scope的5个类型作用
- 默认值为compile,不配置也存在。
参与项目的编译,测试。
打包时会包含进去
<scope>compile</scope>
- runtime参与打包
- provided,不会被打包,作用在编译测试
<scope>provided</scope>
- import只能用在dependencyManagement中,用来解决maven单继承和公共依赖问题,例如需要继承多个父类,而maven只支持单继承,此时在dependencyManagement中添加即可
<scope>import</scope>
- test不会被打包,只作用在测试时
- system不参与打包
pom依赖
- parent
parent包中relativePath的作用
指定依赖jar包的获取地址
获取顺序:
relativePath路径—>本地仓库—>远程仓库
如果relativePath为空,则直接从本地仓库或远程仓库获取jar包
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
- properties
相当于pom依赖的配置文件
当多个依赖的版本号需要重复填写时,可以把版本号写在此处,后面调用即可
<properties>
<!--文件拷贝时的编码-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!--编译时的编码-->
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<java.version>1.8</java.version>
<spring.aop>5.1.3.RELEASE</spring.aop>
</properties>
<!--调用方法如下-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.aop}</version>
</dependency>
dependencyManagement
相当于jar包的版本管理库,如果需要保持项目中jar包版本一致,可以在此处声明版本号,则下方引入依赖时可以省略版本号
此处为固定写法,不需要变动
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<!-- type属性用于指定maven使用maven pom plugin插件处理 -->
<type>pom</type>
<!-- import属性只能用在dependencyManagement -->
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
配置远程仓库
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>