
本文详解 Jenkins 构建失败的根本原因(systemPath 依赖路径不一致 + 资源复制配置错误),提供两种生产级解决方案:推荐使用 mvn install:install-file 统一安装至本地仓库,辅以 spring-boot-maven-plugin 的 includeSystemScope=true 配置,并指出 maven-resources-plugin 错误指向 /BOOT-INF/lib/ 的致命问题。
本文详解 jenkins 构建失败的根本原因(`systempath` 依赖路径不一致 + 资源复制配置错误),提供两种生产级解决方案:推荐使用 `mvn install:install-file` 统一安装至本地仓库,辅以 `spring-boot-maven-plugin` 的 `includesystemscope=true` 配置,并指出 `maven-resources-plugin` 错误指向 `/boot-inf/lib/` 的致命问题。
Jenkins 构建失败的核心症结在于:systemPath 依赖不具备可移植性,且 maven-resources-plugin 的
更关键的是,你在
<resource> <directory>lib</directory> <targetPath>/BOOT-INF/lib/</targetPath> <!-- ❌ 错误!绝对路径非法 --> <includes><include>**/*.jar</include></includes> </resource>
Maven 的
✅ 正确解法分两种,按推荐优先级排序:
方案一(强烈推荐):将本地 JAR 安装至 Maven 本地仓库(CI/CD 友好)
此方案彻底规避路径硬编码,确保 Jenkins、团队成员、容器环境行为完全一致。
步骤 1:在项目根目录下创建安装脚本 install-local-jar.sh
Java Maven 项目审查工作流的通用输入处理。当 Java Maven 项目以 ZIP压缩包或 GitLab 仓库 URL 形式提供且需要...时使用。
#!/bin/bash # 将 lib/ 下所有 JAR 安装到本地仓库(适配 Jenkins 工作空间) mvn install:install-file \ -Dfile=ruoyi-admin/lib/cesiumlanguagewriter-2.20.1.jar \ -DgroupId=cesiumlanguagewriter \ -DartifactId=cesiumlanguagewriter \ -Dversion=2.20.1 \ -Dpackaging=jar \ -DgeneratePom=true
步骤 2:修改 Jenkins 构建前执行命令 在 Jenkins 任务的 “构建” 步骤中,添加 Shell 命令:
chmod +x install-local-jar.sh ./install-local-jar.sh
步骤 3:精简 pom.xml,移除 system 依赖
<!-- 替换原 system 依赖为标准依赖 --> <dependency> <groupId>cesiumlanguagewriter</groupId> <artifactId>cesiumlanguagewriter</artifactId> <version>2.20.1</version> </dependency>
✅ 优势:无路径风险、版本受控、可被子模块继承、Jenkins 自动识别。
方案二(临时兼容):修复 system 依赖 + 正确打包配置
若必须保留 system 依赖,请严格修正以下两点:
① 修正 systemPath 路径(关键!)
使用 ${pom.basedir} 替代 ${project.basedir},确保始终指向当前 POM 所在目录:
<dependency>
<groupId>cesiumlanguagewriter</groupId>
<artifactId>cesiumlanguagewriter</artifactId>
<version>2.20.1</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/cesiumlanguagewriter-2.20.1.jar</systemPath>
</dependency>② 删除错误的
移除整个
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 必须开启,否则 system 依赖不会打入 BOOT-INF/lib -->
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>⚠️ 注意事项:
- system 依赖无法传递给其他模块,仅限当前模块;
- Jenkins 构建前需确保 ruoyi-admin/lib/ 目录及 JAR 文件已通过 Git 提交(.gitignore 不应忽略 lib/);
- Maven 3.5+ 已将 system scope 标记为 deprecated,长期项目请迁移至方案一或私有 Nexus 仓库。
总结:本地 JAR 引入不是“能跑就行”,而是工程可靠性的试金石。方案一通过标准化安装实现环境一致性,是 CI/CD 的黄金实践;方案二虽可救急,但需严守路径与插件配置规范。切勿再使用绝对 targetPath 或盲目信任 ${project.basedir} —— 这正是 Jenkins 与本地环境差异的根源。

















