maven父子多模块版本管理(解决方案)
- 现象:
- 我们在创建项目时往往会创建一个父项目多个子module.父子项目
- 想统一管理所有子模块的版本号有多种方案.如:在父项目中<properties>引入一个变量,所有的子模块引入.
- 但是上述的方案有缺点:
- 最终解决方案:
- maven项目配置:
<build>
<plugins>
<!--多模块Maven项目统一修改版本号-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
</plugins>
</build>
- idea中项目打包
- 最终效果:会修改所有module的pom文件中的版本号.
maven打包前端项目
示例文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>demo-groupId</groupId>
<artifactId>demo-artifactId-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>demo-artifactId</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<node.version>v22.9.0</node.version>
<pnpm.version>9.11.0</pnpm.version>
<sonar.sources>src</sonar.sources>
<frontend-maven-plugin.version>1.15.1</frontend-maven-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<skip>false</skip>
<nodeVersion>${node.version}</nodeVersion>
<pnpmVersion>${pnpm.version}</pnpmVersion>
<pnpmInheritsProxyConfigFromMaven>false</pnpmInheritsProxyConfigFromMaven>
<nodeDownloadRoot>https://npmmirror.com/mirrors/node/</nodeDownloadRoot>
<npmDownloadRoot>https://npmmirror.com/mirrors/npm/</npmDownloadRoot>
<pnpmDownloadRoot>https://registry.npmmirror.com/pnpm/-/</pnpmDownloadRoot>
<!-- <pnpmRegistryURL>https://registry.npmmirror.com</pnpmRegistryURL>-->
<npmRegistryURL>https://registry.npmmirror.com</npmRegistryURL>
</configuration>
<executions>
<execution>
<id>install node and pnpm</id>
<goals>
<goal>install-node-and-pnpm</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<pnpmVersion>${pnpm.version}</pnpmVersion>
</configuration>
</execution>
<execution>
<id>pnpm install</id>
<goals>
<goal>pnpm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>pnpm run build:dev</id>
<goals>
<goal>pnpm</goal>
</goals>
<configuration>
<arguments>run build:dev</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>