maven常见问题汇总(疑难杂症)

在Maven项目中,管理多个子模块的版本号可以通过在父项目配置`<properties>`标签来实现,但这种方法存在不便。更优的解决方案是利用`versions-maven-plugin`插件,通过在`<build><plugins>`部分配置该插件,可以方便地批量修改所有模块的版本号,简化版本管理过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mengchanmian

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值