一 dependencyManagement与dependencies区别:
在父模块中:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
</dependencies>
</dependencyManagement>
那么在子模块中只需要<groupId>和<artifactId>即可,如:
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
1)Dependencies相对于dependencyManagement,所有生命在dependencies里的依赖都会自动引入,并默认被所有的子项目继承。
2)dependencyManagement里只是声明依赖,并不自动实现引入,因此子项目需要显示的声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本
二、spring-boot-starter-parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
pom文件引用spring-boot-starter-parent后,并不会引入任何包,只是用来统一管理 <dependency>引入包的版本。因此有spring-boot-starter-parent, <dependency>就不需要<version>版本配置。
三、build标签
build实例
<build>
<resources>
</resource>
<resource>
<!--从此目录下读取全部以.properties和.xml开头的文件-->
<directory>src/main/java/</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.5.RELEASE</version>
<configuration>
<mainClass>com.xx.xx</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
3.1 Resources配置
<build>
...
<resources>
<resource>
<targetPath>META-INF/plexus</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/plexus</directory>
<includes>
<include>configuration.xml</include>
</includes>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<testResources>
...
</testResources>
...
</build>
- resources
- 一个resources元素的列表。每一个都描述与项目关联的文件是什么和在哪里
- targetPath
- 指定build后的resource存放的文件夹,默认是basedir。
- 通常被打包在jar中的resources的目标路径是META-INF
- filtering
- true/false,表示为这个resource,filter是否激活
- directory
- 定义resource文件所在的文件夹,默认为${basedir}/src/main/resources
- includes
- 指定哪些文件将被匹配,以*作为通配符
- excludes
- 指定哪些文件将被忽略
- testResources
- 定义和resource类似,只不过在test时使用
directory和includes 为必填项
3.2 plugins和pluginManagement标签
<!-- 父pom声明插件,并没有引入插件 -->
<build>
<finalName>loan-startup</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<!-- 子pom引入插件-->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
1、两者的区别,和我们前面研究过的dependencies和dependencyManagement的区别非常类似。
plugins下的plugin是真实使用的,而pluginManagement下的plugins下的plugin则仅仅是一种声明,即你在项目中的pluginManagement下声明了插件,maven不会加载该插件。
3、子项目中可以对pluginManagement下的plugin进行信息的选择、继承、覆盖等。