前言
Jar包管理绕不开Maven, Maven的使用必定设计私服Nexus,那么Maven私服是什么,为什么我们开发Spring boot项目需要它?怎么来搭建自己的私服呢?笔者从一个实际工作遇到的问题着手,与大家分享我了解的Nexus私服小知识。
问题描述
一个沉寂了4个月CICD流水线走到Maven编译的时候,突然报错了:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.xxx.xxxx:dam:1.0-SNAPSHOT: Could not find artifact com.xxx.xxxx:foundation:pom:2.0.1 in nexus (http://xxx.yyy.zzz:8081/nexus/content/groups/public) and 'parent.relativePath' points at wrong local POM @ line 6, column 13
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.xxx.xxxx:dam:1.0-SNAPSHOT (/home/jenkins/workspace/dam/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.xxx.xxxx:dam:1.0-SNAPSHOT: Could not find artifact com.xxx.xxxx:foundation:pom:2.0.1 in nexus (http://xxx.yyy.zzz:8081/nexus/content/groups/public) and 'parent.relativePath' points at wrong local POM @ line 6, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
日志显示foundation这个pom在私服里面(http://xxx.yyy.zzz:8081/nexus/content/groups/public)找不到了。但是6月份的编辑还是好好的,这是什么鬼?我只知道Nexus在中间有迁移过。但是我通过Nexus页面搜索关键字“foundation”,这个pom是能搜到的。不过是在release仓库中,/nexus/content/groups/public
这个目录下的确没有,那项目为什么去groups/public下面找呢?这涉及Nexus的原理,让我们先了解一下这方面的知识。
Nexus安装后默认有三个本地仓库,release、snapshot、3rd party
- Release: 存放稳定版的jar
- Snapshot: 存放快照版本
- 3rd Party: 存放自己上传的第三方jar,比如jdbc驱动
然后仓库类型又分为三种
- hosted: 本地仓库,包括上面的release、snapshot、3rd party
- proxy: 代理仓库,用代理远程的公共仓库,比如中央仓库、阿里云的仓库等
- group:仓库组,用来分组hosted和proxy,避免项目中引入多个repository
看到这里笔者基本猜到原因了,下面我捋捋项目的配置,已经maven的setting配置。确认问题原因。
maven的setting配置
<servers>
<server>