多模块统一管理
说明:flatten-maven-plugin 插件的统一更新的功劳
注意点:建议使用环境配置profiles,profiles的properties里面要加revision版本;子级的pom版本中的parent中的版本也使用revision,然后自己的版本不写,跟父级版本一致
父级pom(基础配置):
此处是必须的最基础的配置,其他的配置信息未列出,需要根据自身情况来
<build>
<plugins>
<plugin>
<!-- flatten-maven-plugin 插件可快速更新子级所有包版本 -->
<artifactId>flatten-maven-plugin</artifactId>
<configuration>
<!-- 是否更新pom文件,此处还有更高级的用法 -->
<flattenMode>resolveCiFriendliesOnly</flattenMode>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<execution>
<goals>
<goal>flatten</goal>
</goals>
<id>flatten</id>
<phase>process-resources</phase>
</execution>
<execution>
<goals>
<goal>clean</goal>
</goals>
<id>flatten.clean</id>
<phase>clean</phase>
</execution>
</executions>
<groupId>org.codehaus.mojo</groupId>
<version>1.1.0</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<id>attach-sources</id>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<version>3.2.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<modules>
<!-- start module(此module只是个例子,自己需求来建,此处不讨论模型脚手架) -->
<module>start</module>
</modules>
<profiles>
<profile>
<activation>
<!--这个字段表示默认激活-->
<activeByDefault>true</activeByDefault>
</activation>
<id>dev</id>
<properties>
<!-- 由于flatten-maven-plugin,所以版本号只能为${revision} -->
<revision>0.0.1-SNAPSHOT</revision>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<revision>0.0.1-SNAPSHOT</revision>
</properties>
</profile>
<profile>
<id>pre</id>
<properties>
<revision>0.0.1-RELEASE</revision>
</properties>
</profile>
<profile>
<id>master</id>
<properties>
<revision>0.0.1-RELEASE</revision>
</properties>
</profile>
</profiles>
<!-- 此处由于flatten-maven-plugin,所以版本号只能为${revision} -->
<version>${revision}</version>
<properties>
<!--可能第一次编辑会有找不到revision版本的问题,所以需要此处加一个,
只需要第一次编译通过后,这个配置就可以去掉了,当然不去掉也可以,默认是使用的的profile里激活的配置,这里也不需要每次更新它-->
<revision>0.0.1-SNAPSHOT</revision>
</properties>
....
....
子级pom(基础配置):
start.pom.xml
<parent>
<artifactId>...</artifactId>
<groupId>...</groupId>
<version>${revision}</version>
</parent>
<artifactId>start</artifactId>
....
....
deploy发布到仓库跳过模块
一般我们给三方或二方提供服务包的时候,需要将某个包deploy到远程仓库中,例如是提供的FeignClient包,因为我们加上前面的统一版本的配置,所以在父pom上直接deploy时,不需要提供给三方或二方的子module里加上跳过deploy
某个pom:
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>