Nexus 制品库管理实践02 搭建Maven私服(代理仓库)

网友投稿 1106 2022-11-30

Nexus 制品库管理实践02 搭建Maven私服(代理仓库)

Nexus 制品库管理实践02 搭建Maven私服(代理仓库)

在搭建好nexus之后会帮你创建好maven的仓库,这个就相对于私服,代理进来就可以直接使用了

搭建Maven私服(代理仓库)

为什么要搭建maven私服呢?

默认开发同学在进行开发的时候会使用一些包管理工具,例如:maven、ant、gradle这些都是常见项目编译构建工具 。这些工具可以理解为是一个命令行工具, 本身不会存储任何依赖包,而是通过公网官方的仓库中-当前项目构建所需要的包。 (内网的速度要比公网快,这会直接影响管道的构建速度)

maven私服指的是什么?

使用私服,就是在企业内部建立单一的可信源, 例如:我们在公司通过nexus创建一个代理仓库, 将公网仓库中的maven包代理到内网仓库中。 这样整个公司的同学就可以直接访问内网的私服进行-构建依赖包。(减少了引入不信任依赖的风险)

代理仓库不会一下子把公网仓库中的所有包-到本地,而是按需缓存。 例如: 此时我需要使用aa这个包, 如果代理仓库中没有, 则请求外部服务器-这个包并进行缓存。第二次访问的时候,就直接访问代理仓库了。

搭建制品库(本地仓库)

本地仓库:对于Maven为例, RELEASE类型仓库(存放制品稳定版)SNAPSHOT类型仓库(存放制品开发版)。用于存储公司内部业务开发所生成的制品。

切记:release类型的仓库只能存放release版本的包。

安装nexus后,默认存在以下图中的仓库, 这些仓库是官方默认配置好的maven私服。(可以直接使用)

将maven仓库地址替换阿里云的源

[root@jenkins-master ~]# vim /usr/local/apache-maven-3.8.1/conf/settings.xml alimaven central aliyun maven

清空本地的maven包

[root@jenkins-master ~]# rm -rf /root/.m2/

[root@jenkins-master devops-maven-service-master]# mvn clean package[INFO] Scanning for projects...Downloading from alimaven: [ERROR] Some problems were encountered while processing the POMs:[FATAL] Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.4.4 from/to alimaven (authentication failed for status: 401 Unauthorized and 'parent.relativePath' points at no local POM @ line 5, column 10 @ [ERROR] The build could not read 1 project -> [Help 1][ERROR] [ERROR] The project com.example:demo:0.0.1-SNAPSHOT (/root/devops-maven-service-master/pom.xml) has 1 error[ERROR] Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.4.4 from/to alimaven (authentication failed for status: 401 Unauthorized and 'parent.relativePath' points at no local POM @ line 5, column 10 -> [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] [Help 2] devops-maven-service-master]# [root@jenkins-master devops-maven-service-master]#

这里认证失败,需要开启匿名访问

[root@jenkins-master devops-maven-service-master]# mvn clean package[INFO] Scanning for projects...Downloading from alimaven: from alimaven: (8.6 kB at 3.0 kB/s)Downloading from alimaven: from alimaven: (108 kB at 113 kB/s)Downloading from alimaven: from alimaven: (4.1 kB at 8.9 kB/s)Downloading from alimaven: from alimaven: (5.3 kB at 12 kB/s)Downloading from alimaven: Repository:​​

刚开始仓库里面肯定是没有东西的,随着经常使用会帮你挨个的去缓存

如果你没有私服,可以赶紧去创建一个

这里有个版本,release版本和snapshot版本,release是正式版本,snapshot是开发版本。比如Jenkins就有很多版本,有个稳定的版本和每周迭代的版本,正真发给用户的是一个稳定的版本,稳定的版本这里是release版本。然后输入代理仓库的地址。仓库地址:​​Central Repository:​​

复制这个地址就可以配置到你得maven里面了 ,刚刚创建是没有包的,这个是按需的,需要什么包再-什么包,然后进行缓存。

可以看到很简答,配置好仓库,设置代理的地址就行了。

[root@jenkins-agent ~]# rm -rf .m2/

[ERROR] The project com.example:demo:0.0.1-SNAPSHOT (/root/devops-maven-service-master/pom.xml) has 1 error[ERROR] Non-resolvable parent POM for com.example:demo:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.4.4 from/to alimaven (authentication failed for status: 401 Unauthorized and 'parent.relativePath' points at no local POM @ line 5, column 10 -> [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] [Help 2] devops-maven-service-master]# mvn clean package[INFO] Scanning for projects...Downloading from alimaven: from alimaven: (8.6 kB at 7.1 kB/s)Downloading from alimaven: from alimaven: (108 kB at 128 kB/s)Downloading from alimaven: from alimaven: (4.1 kB at 12 kB/s)Downloading from alimaven: from alimaven: (5.3 kB at 14 kB/s)Downloading from alimaven: from alimaven: (17 kB at 43 kB/s)Downloading from alimaven: http://139.198.166.235:8082/repository/mymavenrepo/org/codehaus/groovy/groovy-bom/2.5.14/groovy-bom-2.5.14.pom

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SonarQube 04 SonarScanner的使用 Web Go项目扫描
下一篇:微服务 全链路监控工具pinpoint 重新编译带有pinpoint agent的源代码
相关文章

 发表评论

暂时没有评论,来抢沙发吧~