Jenkins部署之mvn<goals>-rf:zzsd-common maven编译错误

 遇到这个问题是因为maven编译错误

经过检查,是Build-Root POM下pom.xml路径没有添加子路径,添加zzsd-common/pom.xml即可

 

写一个jenkins batch脚本,将pom文件中的<revision>1.0.12</revision> 修改为指定的版本号,pom文件为: <?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"> <artifactId>common-data-management-system</artifactId> <version>${revision}</version> <groupId>com.tplink.smb.omada</groupId> <modelVersion>4.0.0</modelVersion> <modules> <module>common-data-management-system-common</module> <module>common-data-management-system-logging</module> <module>common-data-management-system-system</module> <module>common-data-management-system-tools</module> </modules> <name>common-data-management-system</name> <packaging>pom</packaging> <parent> <artifactId>spring-boot-starter-parent</artifactId> <groupId>org.springframework.boot</groupId> <version>2.7.18</version> </parent> <properties> <revision>1.0.12</revision> <commons-pool2.version>2.11.1</commons-pool2.version> <druid.version>1.2.19</druid.version> <fastjson2.version>2.0.54</fastjson2.version> <java.version>17</java.version> <logback.version>1.2.9</logback.version> <mapstruct.version>1.4.2.Final</mapstruct.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version> </properties> <build> <plugins> <!-- 打包时跳过测试 --> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> <groupId>org.apache.maven.plugins</groupId> </plugin> <!-- 版本号管理插件 --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>flatten-maven-plugin</artifactId> <version>${flatten-maven-plugin.version}</version> <configuration> <updatePomFile>true</updatePomFile> <flattenMode>resolveCiFriendliesOnly</flattenMode> </configuration> <executions> <execution> <id>flatten</id> <phase>process-resources</phase> <goals> <goal>flatten</goal> </goals> </execution> <execution> <id>flatten.clean</id> <phase>clean</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <dependencies> <!--Spring boot 核心--> <dependency> <artifactId>spring-boot-starter-data-jpa</artifactId> <groupId>org.springframework.boot</groupId> </dependency> <!-- Spring boot websocket --> <dependency> <artifactId>spring-boot-starter-websocket</artifactId> <groupId>org.springframework.boot</groupId> </dependency> <!--Spring boot Web容器--> <dependency> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <!-- 去掉Jackson依赖,用fastjson --> <exclusion> <artifactId>spring-boot-starter-json</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> <groupId>org.springframework.boot</groupId> </dependency> <!--Spring boot 测试--> <dependency> <artifactId>spring-boot-starter-test</artifactId> <groupId>org.springframework.boot</groupId> <scope>test</scope> </dependency> <!--Spring boot 安全框架--> <dependency> <artifactId>spring-boot-starter-security</artifactId> <groupId>org.springframework.boot</groupId> </dependency> <!-- spring boot 缓存 --> <dependency> <artifactId>spring-boot-starter-cache</artifactId> <groupId>org.springframework.boot</groupId> </dependency> <!--Spring boot Redis--> <dependency> <artifactId>spring-boot-starter-data-redis</artifactId> <groupId>org.springframework.boot</groupId> </dependency> <!--Spring boot redisson--> <dependency> <artifactId>redisson-spring-boot-starter</artifactId> <groupId>org.redisson</groupId> <version>3.17.1</version> </dependency> <!--spring boot 集成redis所需common-pool2--> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 --> <dependency> <artifactId>commons-pool2</artifactId> <groupId>org.apache.commons</groupId> <version>${commons-pool2.version}</version> </dependency> <dependency> <artifactId>commons-lang3</artifactId> <groupId>org.apache.commons</groupId> </dependency> <!-- Swagger UI 相关 --> <dependency> <artifactId>knife4j-spring-boot-starter</artifactId> <exclusions> <!-- 去掉 swagger-annotations 依赖,避免冲突 --> <exclusion> <artifactId>swagger-annotations</artifactId> <groupId>io.swagger</groupId> </exclusion> </exclusions> <groupId>com.github.xiaoymin</groupId> <version>3.0.3</version> </dependency> <!-- 添加swagger-annotations依赖 --> <dependency> <artifactId>swagger-annotations</artifactId> <groupId>io.swagger</groupId> <version>1.5.22</version> </dependency> <!--Mysql依赖包--> <dependency> <artifactId>mysql-connector-j</artifactId> <groupId>com.mysql</groupId> <scope>runtime</scope> <version>9.2.0</version> </dependency> <!-- druid数据源驱动 --> <dependency> <artifactId>druid-spring-boot-starter</artifactId> <groupId>com.alibaba</groupId> <version>${druid.version}</version> </dependency> <!-- IP地址解析库 --> <dependency> <artifactId>mica-ip2region</artifactId> <groupId>net.dreamlu</groupId> <version>2.7.18.9</version> </dependency> <!--lombok插件--> <dependency> <artifactId>lombok</artifactId> <groupId>org.projectlombok</groupId> <optional>true</optional> </dependency> <!-- excel工具 --> <dependency> <artifactId>poi</artifactId> <groupId>org.apache.poi</groupId> <version>5.4.0</version> </dependency> <dependency> <artifactId>poi-ooxml</artifactId> <groupId>org.apache.poi</groupId> <version>5.4.0</version> </dependency> <dependency> <artifactId>xercesImpl</artifactId> <groupId>xerces</groupId> <version>2.12.2</version> </dependency> <!-- fastjson2 --> <dependency> <artifactId>fastjson2</artifactId> <groupId>com.alibaba.fastjson2</groupId> <version>${fastjson2.version}</version> </dependency> <dependency> <artifactId>fastjson2-extension-spring5</artifactId> <groupId>com.alibaba.fastjson2</groupId> <version>${fastjson2.version}</version> </dependency> <!-- Java图形验证码 --> <dependency> <artifactId>easy-captcha</artifactId> <groupId>com.github.whvcse</groupId> <version>1.6.2</version> </dependency> <dependency> <artifactId>commons-text</artifactId> <groupId>org.apache.commons</groupId> <version>1.13.0</version> </dependency> <!--mapStruct依赖--> <dependency> <artifactId>mapstruct</artifactId> <groupId>org.mapstruct</groupId> <version>${mapstruct.version}</version> </dependency> <dependency> <artifactId>mapstruct-processor</artifactId> <groupId>org.mapstruct</groupId> <scope>provided</scope> <version>${mapstruct.version}</version> </dependency> <dependency> <artifactId>javax.inject</artifactId> <groupId>javax.inject</groupId> <version>1</version> </dependency> </dependencies> <distributionManagement> <repository> <id>smb-nexus</id> <name>smb releases repository</name> <url>${smb.repository.url}</url> </repository> <snapshotRepository> <id>smb-nexus-snapshots</id> <name>smb snapshots repository</name> <url>${smb.snapshot-repository.url}</url> </snapshotRepository> </distributionManagement> <!-- <repositories>--> <!-- <repository>--> <!-- <id>public</id>--> <!-- <name>aliyun nexus</name>--> <!-- <releases>--> <!-- <enabled>true</enabled>--> <!-- </releases>--> <!-- <url>http://maven.aliyun.com/nexus/content/groups/public/</url>--> <!-- </repository>--> <!-- </repositories>--> <url>https://eladmin.vip</url> </project>
最新发布
12-11
你可以使用 Jenkins 的 **Pipeline** 或 **自由风格项目** 来执行一个批处理脚本(Batch Script),在 Windows 环境下修改 `pom.xml` 中的 `<revision>1.0.12</revision>` 为指定版本号。 下面是一个适用于 Jenkins 构建步骤的 **Windows Batch 脚本**,它会: - 接收一个参数作为目标版本号(如通过 Jenkins 参数化构建传入) - 使用 PowerShell 替换 XML 文件中的 `<revision>` 值 - 保留原始格式和注释(避免破坏 XML 结构) --- ### ✅ Jenkins Batch 脚本:修改 pom.xml 中的 revision 版本 ```batch @echo off :: 设置输入参数:新版本号 set NEW_REVISION=%1 if "%NEW_REVISION%"=="" ( echo 错误:未提供新版本号,请以参数形式传入,例如:build.bat 1.0.13 exit /b 1 ) echo 正在将 pom.xml 中的 revision 更新为 %NEW_REVISION% :: 使用 PowerShell 修改 pom.xml 中的 <revision> 节点 powershell -Command "$pom = [xml](Get-Content 'pom.xml'); $pom.project.properties.revision = '%NEW_REVISION%'; $pom.Save('pom.xml');" if %errorlevel% == 0 ( echo 成功更新 pom.xml 中的 revision 为 %NEW_REVISION% ) else ( echo 更新失败!请检查 pom.xml 是否存在或格式是否正确。 exit /b 1 ) ``` --- ### 🔍 脚本解释: - `set NEW_REVISION=%1`:从命令行参数获取新版本号(Jenkins 可配置 `String Parameter` 如 `VERSION=1.0.13`)。 - 使用 `PowerShell` 加载 `pom.xml` 作为 XML 对象进行解析和修改,确保不会破坏结构。 - `$pom.project.properties.revision`:准确指向 `<properties><revision>...</revision></properties>` 节点。 - `$pom.Save(...)`:安全保存文件,保持编码与格式一致。 - 错误检测机制:若出错则退出并返回非零状态码,触发 Jenkins 构建失败。 --- ### 🧪 在 Jenkins 中如何使用? #### 方法一:自由风格项目(FreeStyle Job) 1. 创建参数化构建,添加 `String Parameter`,名称设为 `VERSION` 2. 构建步骤选择 “Execute Windows batch command” 3. 粘贴上述脚本,并调用参数: ```batch call update_revision.bat %VERSION% ``` 或者直接内联写: ```batch set NEW_REVISION=%VERSION% ... ``` #### 方法二:Pipeline(推荐) ```groovy pipeline { agent { label 'windows' } // 必须是 Windows 节点,支持 cmd/powershell parameters { string(name: 'VERSION', defaultValue: '1.0.13', description: '要设置的 revision 版本号') } stages { stage('Update Revision') { steps { script { bat """ set NEW_REVISION=${params.VERSION} powershell -Command ^ \$pom = [xml](Get-Content 'pom.xml'); ^ \$pom.project.properties.revision = '${params.VERSION}'; ^ \$pom.Save('pom.xml'); echo 更新版本号为 ${params.VERSION} 完成。 """ } } } stage('Build with Maven') { steps { bat 'mvn clean package -Drevision=${VERSION}' } } } } ``` > 💡 注意事项: > - 确保 Jenkins 节点有写权限修改 `pom.xml` > - 若使用 Git 源码管理,建议在构建前备份或提交更改(可选 push 回仓库) --- ### ✅ 验证效果 修改后 `<properties>` 中的内容应变为: ```xml <properties> <revision>1.0.13</revision> ... </properties> ``` 且 `<version>${revision}</version>` 会被 Maven 和 flatten 插件自动识别为最终版本。 --- ### ⚠️ 补充建议 如果你还想同时更新其他占位符(比如 `${smb.repository.url}`),也可以扩展此脚本。但当前只聚焦于 `<revision>`。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值