1. 父pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.cloud.crea</groupId>
<artifactId>crea-cloud</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<name>Common-Business</name>
<properties>
<java.version>1.8</java.version>
<spring.boot.version>2.1.9.RELEASE</spring.boot.version>
<crea-common.version>1.0.1</crea-common.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
<com-alibaba-cloud.version>2.1.1.RELEASE</com-alibaba-cloud.version>
<spring-platform-bom.version>Cairo-SR8</spring-platform-bom.version>
<mysql-connector.version>8.0.18</mysql-connector.version>
<spring-boot-admin.version>2.1.6</spring-boot-admin.version>
<mybatis-plus.version>3.2.0</mybatis-plus.version>
<mybatis.version>3.5.7</mybatis.version>
<mybatis-dynamic-datasource.version>3.1.1</mybatis-dynamic-datasource.version>
<dockerfile.maven.version>1.4.13</dockerfile.maven.version>
<docker-maven-plugin.version>0.4.13</docker-maven-plugin.version>
<docker.baseImage>openjdk:8u212-jre</docker.baseImage>
<docker.volumes>/tmp</docker.volumes>
<docker.image.prefix>crea_cloud</docker.image.prefix>
<docker.host>https://121.40.154.203:2375</docker.host>
<!-- <docker.host>https://39.96.141.0:2375</docker.host>-->
<docker.java.security.egd>-Djava.security.egd=file:/dev/./urandom</docker.java.security.egd>
<docker.java.opts>-Xms128m -Xmx128m</docker.java.opts>
<fastdfs-client>1.26.5</fastdfs-client>
</properties>
<dependencies>
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>${p6spy.version}</version>
</dependency>
</dependencies>
<!--这里只是使用版本控制,设置子pom的版本,并不是真正的引入-->
<dependencyManagement>
</dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>${mybatis-dynamic-datasource.version}</version>
</dependency>
</dependencies>
<!-- 此处省略较多配置设置..... -->
</dependencyManagement>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<pluginManagement>
<plugins>
<!--spring boot 插件-->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
<finalName>${project.build.finalName}</finalName>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!--docker 插件-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker-maven-plugin.version}</version>
<configuration>
<!--指定远程 docker api地址-->
<dockerHost>${docker.host}</dockerHost>
<!--指定生成的镜像名-->
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<!--指定标签-->
<imageTags>
<imageTag>latest</imageTag>
</imageTags>
<!-- 表示项目根目录,即包含pom.xml文件的目录-->
<!-- 指定 Dockerfile 路径 ${project.basedir}:项目根路径下-->
<dockerDirectory>${pom.basedir}</dockerDirectory>
<dockerCertPath>E:\桌面文件\目录\活力狮公有云docker证书\client_pem203</dockerCertPath>
<!-- <dockerCertPath>E:\桌面文件\目录\docker-ca-lsyx</dockerCertPath>-->
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<!--根项目不需要docker build子项目不要继续,否则子项目也会不docker build-->
<inherited>false</inherited>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skipDockerBuild>true</skipDockerBuild>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>ge-releases</id>
<url>http://192.168.0.82:30102/repository/ge-releases/</url>
</repository>
<snapshotRepository>
<id>ge-snapshots</id>
<url>http://192.168.0.82:30102/repository/ge-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<modules>
<module>crea-common</module>
<module>crea-gateway</module>
<module>crea-monitor</module>
<module>crea-auth</module>
<module>crea-job</module>
<module>crea-service-tool</module>
<module>crea-server</module>
</modules>
</project>
2. 子pom.xml文件
3. 父类dependencyManagement标签
使用dependencyManagement标签可以让所有在子项目中引用一个依赖而不用显示的列出版本号。
maven会沿着父子层级往上走,直到找到一个拥有dependencyManagement元素的项目,然后他就会使用dependencyManagement标签中指定的版本号。
如果有多个子项目都引用一样的依赖,则可以避免在每个使用的子项目中都声明一个版本号,这样当想升级或者切换到另一个版本时,只需要在顶层父容器中更新,而不需要一个一个子项目修改。
注意:
- dependencyManagement只是声明依赖,并不是先引入,因此子项目需要显示的声明需要用的依赖,如果不再子项目中声明依赖,是不会从副项目中继承下来的
- 如果子项目需要一个自己单独的版本,只需要在子项目pom中声明自己想要的version即可