mavenarchiver离线安装(离线环境解决maven编译外网下包问题)
引言
近日一直忙着做持续集成 ,处于安全性考虑 ,需要在离线环境运行 。项目依托Jenkins做Java/Python/Vue等工程的镜像构建 ,其中Java工程基本基于Maven ,在外网条件下通过IDEA或者mvn命令均可正常打包 ,原本思路是将本地的repo全量拷贝到服务器 ,再执行同样的mvn命令 ,但实际出发jenkins构建任务时 ,经常build失败 。哪怕在maven的setting.xml中硬性设置<offline>true</offline>,依旧不起作用 。
问题原因探索
maven在执行构建过程中 ,会按照localRepo->privateRepo->mirrorRepo->centralRepo依次去解决包缺失问题 ,并最终下载到localRepo 。因为是全量拷贝windows的localRepo,里边存在了大量的_remote.repositories文件 ,此文件直接影响了部分jar的同步问题 ,导致哪怕localRepo明明已经有了jar包,还是固执地去上级仓库拉包 。然而我们没有环境配置nexus和mirror ,故只能向centralRepo找寻jar包 ,导致build失败 。
行之有效的解决办法
1.在不设置nexus的情况下,直接伪造一个mirror源 ,指向服务器localRepo ,需要在maven的setting.xml文件中 ,新增一个mirror ,格式如下 。
<mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>central</id> <mirrorOf>*</mirrorOf> <name>central</name> <url>file:///data/maven_repo/Mvn363</url> </mirror> </mirrors>2.删除localRepo下所有的_remote.repositories文件
# 查询所有的_remote.repositories find . -name _remote.repositories # 删除当前目录下所有的_remote.repositories find . -name _remote.repositories | xargs -I {} rm -fr {}3.再次触发jenkins构建任务 ,无误 。
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!