0
点赞
收藏
分享

微信扫一扫

Nexus同步下载maven中央仓库里的包到本地

凉夜lrs 2022-11-10 阅读 90

最近发现公司的Jenkins打包时都需要通过访问​​https://maven.aliyun.com/repository/public​​​ 去下载一些依赖包,但是局域网里之前搭建了Nexus的,我去nexus上一看,全是公司内部开发的基础包和第三方合作机构的包,感觉这种模式有问题,后来我百度上网看了下,发现标准模式是(原谅一下我的孤陋寡闻,毕竟不是专门干配置管理的,半路接手真的头疼):开发人员全部通过Nexus下载依赖包,Nexus本地没有的情况,通过代理下载Maven中央仓库的文件到Nexus本地,然后开发人员再从Nexus上拉到自己的电脑上。以下为拓扑图:来自​​http://t.zoukankan.com/huangwentian-p-9182819.html​​

Nexus同步下载maven中央仓库里的包到本地_Nexus

这种情况下,不管来了多少开发人员,只要指向内部私仓,不光下载速度快而且稳定,避免了公司内部多台电脑频繁访问互联网maven仓,不仅消耗大量公带宽资源,而且下载的资源也不稳定。

以下为主要的配置步骤:

1、进入nexus的管理界面,将Central的远程地址改为阿里云的地址:​​https://maven.aliyun.com/repository/public/​​ ,按照下图改

Nexus同步下载maven中央仓库里的包到本地_maven_02

2、改下apache-snapshots的配置,我感觉这个不影响,算了统一改了吧,https://maven.aliyun.com/repository/apache-snapshots/

Nexus同步下载maven中央仓库里的包到本地_jenkins_03

3、为了以防万一,我自己还多建了一个代理做测试


Nexus同步下载maven中央仓库里的包到本地_Nexus_04

4、将相关仓库加到组中


Nexus同步下载maven中央仓库里的包到本地_jenkins_05


好了,接下来到jenkins上修改apache-maven-3.5.4/conf下的配置文件,主要的内容如下

<localRepository>/app/repository</localRepository>


<pluginGroups>

</pluginGroups>


<proxies>


</proxies>

<servers>

<server>
<id>releases</id>
<username>admin</username>
<password>k123456K</password>
</server>

<server>
<id>snapshots</id>
<username>admin</username>
<password>k123456K</password>
</server>

</servers>
<mirrors>

<mirror>
<id>nexus</id>
<name>nexus</name>
<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>



</mirrors>

<profiles>

<profile>

<activation>
<activeByDefault>true</activeByDefault>
</activation>

<repositories>
<repository>
<id>release</id>
<name>release</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
</repository>

<repository>
<id>thirdparty</id>
<name>thirdparty</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
</repository>
<repository>
<id>snapshots</id>
<name>snapshots</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>

</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<name>snapshots</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>

</profile>

</profiles>

</settings>

好了,所有的步骤完成了。结果jenkins打包的时候,一直提示包不存在,就是不去阿里云Maven中央库上下载文件,各种百度都找不到,头疼得很,后来从nexus上的日志下手,发现一直连不上(后来可以下载中央仓库文件这个日志还是一直在,好像和这个问题没关系)。

jvm 1    | 2022-11-10 10:41:43,455+0800 WARN  [proxy-3-thread-18732] admin org.sonatype.nexus.proxy.maven.maven2.M2Repository - Remote peer of proxy repository "Apache Snapshots" [id=apache-snapshots] threw a org.sonatype.nexus.proxy.ItemNotFoundException exception. - Cause(s): Remote peer of repository M2Repository(id=apache-snapshots) detected as unavailable.

jvm 1    | 2022-11-10 10:42:32,979+0800 INFO  [ar-4-thread-3] admin org.sonatype.nexus.proxy.maven.routing.internal.RemoteScrapeStrategy - Not possible remote scrape of M2Repository(id=apache-snapshots), no scraper succeeded.

jvm 1    | 2022-11-10 10:46:39,488+0800 WARN  [proxy-3-thread-18734] admin org.sonatype.nexus.proxy.maven.maven2.M2Repository - Remote peer of proxy repository "Central" [id=central] threw a org.sonatype.nexus.proxy.ItemNotFoundException exception. - Cause(s): Remote peer of repository M2Repository(id=central) detected as unavailable.

再去看了下nexus上的状态(下图),

Nexus同步下载maven中央仓库里的包到本地_maven_06

不知道是不是和这个有关,后面改了下之前配置

Nexus同步下载maven中央仓库里的包到本地_maven_07

然后无意中点到仓库的‘Rebuild Metadata’,之前好像还点到了‘Expire Cache’,发现可以直接下载了,汗,终于搞定了。

Nexus同步下载maven中央仓库里的包到本地_Nexus_08

以下为jenkins上apache-maven-3.5.4/conf/settings的所有内容

<?xml versinotallow="1.0" encoding="UTF-8"?>


<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocatinotallow="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<!-- TIPS: modify local repository -->
<localRepository>/app/comm/repository</localRepository>


<pluginGroups>

</pluginGroups>


<proxies>


</proxies>

<!-- servers | This is a list of authentication profiles, keyed by the server-id
used within the system. | Authentication profiles can be used whenever maven
must make a connection to a remote server. | -->
<servers>

<server>
<id>releases</id>
<username>admin</username>
<password>k2244444u1K</password>
</server>

<server>
<id>snapshots</id>
<username>admin</username>
<password>k2244444u1K</password>
</server>

</servers>

<!-- mirrors | This is a list of mirrors to be used in downloading artifacts
from remote repositories. | | It works like this: a POM may declare a repository
to use in resolving certain artifacts. | However, this repository may have
problems with heavy traffic at times, so people have mirrored | it to several
places. | | That repository definition will have a unique id, so we can create
a mirror reference for that | repository, to be used as an alternate download
site. The mirror site will be the preferred | server for that repository.
| -->
<mirrors>

<!--<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror> -->



<!--<mirror>
<id>net-cn</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://maven.net.cn/content/groups/public/</url>
</mirror>

<mirror>
<id>ui</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://uk.maven.org/maven2/</url>
</mirror>-->

<!--<mirror>
<id>nexus-aliyun</id>
<mirrorOf>nexus-aliyun</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>

<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>-->

<mirror>
<id>nexus</id>
<name>nexus</name>
<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>



</mirrors>

<!-- profiles | This is a list of profiles which can be activated in a variety
of ways, and which can modify | the build process. Profiles provided in the
settings.xml are intended to provide local machine- | specific paths and
repository locations which allow the build to work in the local environment.
| | For example, if you have an integration testing plugin - like cactus
- that needs to know where | your Tomcat instance is installed, you can provide
a variable here such that the variable is | dereferenced during the build
process to configure the cactus plugin. | | As noted above, profiles can
be activated in a variety of ways. One way - the activeProfiles | section
of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular
value for the property, | or merely testing its existence. Profiles can also
be activated by JDK version prefix, where a | value of '1.4' might activate
a profile when the build is executed on a JDK version of '1.4.2_07'. | Finally,
the list of active profiles can be specified directly from the command line.
| | NOTE: For profiles defined in the settings.xml, you are restricted to
specifying only artifact | repositories, plugin repositories, and free-form
properties to be used as configuration | variables for plugins in the POM.
| | -->
<profiles>

<profile>

<activation>
<activeByDefault>true</activeByDefault>
</activation>

<repositories>
<repository>
<id>release</id>
<name>release</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
</repository>

<repository>
<id>thirdparty</id>
<name>thirdparty</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
</repository>
<repository>
<id>snapshots</id>
<name>snapshots</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>

</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<name>snapshots</name>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>

<url>http://10.50.11.15:8081/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>

</profile>

</profiles>

</settings>

举报

相关推荐

0 条评论