Maven私有仓库搭建以及使用

Maven私有仓库搭建以及使用

参考链接https://www.cnblogs.com/wuwei928/p/10338307.html

一、使用Docker安装Nexus

Docker search nexus

img

docker pull docker.io/sonatype/nexus3

img

mkdir -p /usr/local/nexus3/nexus-data``chown -R 200 /usr/local/nexus3/nexus-data` `docker run -tid -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus -v /usr/local/nexus3/nexus-data:/nexus-data docker.io/sonatype/nexus3

现在已经安装完成了 nexus。

二、登录Nexus进行配置

1、登录nexus

这里的ip是你的服务器ip

访问:http://ip:8081/nexus 使用默认管理员身份登录,帐号:admin,密码:admin123 注意:nexus 3.17版本后初始密码不是admin/admin123。

3.17版本密码改成随机的了,而且登录时候提示密码在/nexus-data/admin.password里

大概在这个位置

在这里插入图片描述

查看密码

vi admin.password

img

注意:登录密码就是这么一大长传的字符串!!!,这不是加密的,当初以为这是加密的,还各种找资料要解密

复制粘贴登录就行了

首次登录后会让你重置密码,重置密码后系统就会自动删除admin.password文件

img

2、进入管理界面

img

  • Browse可以查看当前有多少仓库,搭建好的Nexus,默认会带有一些maven仓库,一般使用这些仓库就足够了。
  • 默认仓库说明

​ maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

​ maven-releases:私库发行版jar,初次安装请将Deployment policy设置为Allow redeploy

​ maven-snapshots:私库快照(调试版本)jar

​ maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml或项目pom.xml中使用

  • 仓库类型

​ Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的,用于方便开发人员自己设定的仓库。maven-public就是一个Group类型的仓库,内部设置了多个仓库,访问顺序取决于配置顺序,3.x默认Releases,Snapshots, Central,当然你也可以自己设置。
​ Hosted:私有仓库,内部项目的发布仓库,专门用来存储我们自己生成的jar文件
​ 3rd party:未发布到公网的第三方jar (3.x去除了)
​ Snapshots:本地项目的快照仓库
​ Releases: 本地项目发布的正式版本
​ Proxy:代理类型,从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage属性的值即被代理的远程仓库的路径),如可配置阿里云maven仓库
​ Central:中央仓库
​ Apache Snapshots:Apache专用快照仓库(3.x去除了)

3、增加新的代理源

第一步 按照步骤添加新的代理源

img

第二步 选择添加maven2的代理

img

第三步 添加代理(Cache统一设置为200天 288000)

img

img

第四步 逐个增加常用代理

[复制代码](javascript:void(0)😉

1. aliyun
http://maven.aliyun.com/nexus/content/groups/public
2. apache_snapshot
https://repository.apache.org/content/repositories/snapshots/
3. apache_release
https://repository.apache.org/content/repositories/releases/
4. atlassian
https://maven.atlassian.com/content/repositories/atlassian-public/
5. central.maven.org
http://central.maven.org/maven2/
6. datanucleus
http://www.datanucleus.org/downloads/maven2
7. maven-central (安装后自带,仅需设置Cache有效期即可)
https://repo1.maven.org/maven2/
8. nexus.axiomalaska.com
http://nexus.axiomalaska.com/nexus/content/repositories/public
9. oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
10.pentaho
https://public.nexus.pentaho.org/content/groups/omni/

[复制代码](javascript:void(0)😉

第五步 设置maven-public 将这些代理加入Group,最好将默认的maven库放到最底下

img

第六步 设置私用仓库可重复发布

​ Nexus安装后自带maven-releases,maven-snapshots两个仓库,用于将生成的jar包发布在这两个仓库中,在实际开发中需要将maven-releases设置为可以重复发布

img

4、Maven配置使用Nexus

修改.m2下面的setting.xml文件配置

4.1 在servers标签下

<!-- 下面的password是我自己设置的 -->
<server>
  <id>releases</id>
  <username>admin</username>
  <password>123456</password>
</server>

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

<server>
  <id>nexus-public</id>
  <username>admin</username>
  <password>123456</password>
</server>

4.2 在profiles标签下

<profile>
      <id>HolliPark</id>
      <repositories>
	  <!--
        <repository>
          <id>nexus</id>
          <name>Public Repositories</name>
          <url>http://10.18.1.21:8081/nexus/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      
        <repository>
          <id>central</id>
          <name>Central Repositories</name>
          <url>http://10.18.1.21:8081/nexus/repository/maven-central/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
	  -->
		
        <repository>
          <id>releases</id>
          <name>Release Repositories</name>
          <url>http://10.18.1.21:8081/nexus/repository/maven-releases/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        
        <repository>
          <id>snapshots</id>
          <name>Snapshot Repositories</name>
          <url>http://10.18.1.21:8081/nexus/repository/maven-snapshots/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      
      <pluginRepositories>
        <pluginRepository>
          <id>nexus-public</id>
          <name>Plugin Repositories</name>
          <url>http://10.18.1.21:8081/nexus/repository/maven-public/</url>
        </pluginRepository>
      </pluginRepositories>
    
 </profile>

4.3 激活——在activeProfiles标签下

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Y43vwNc9-1646375727617)(C:\Users\Yohann\AppData\Roaming\Typora\typora-user-images\image-20220120112514049.png)]

<!--这里的HolliPark要与上面profile下的id一致-->
<activeProfiles>
	<activeProfile>HolliPark</activeProfile>
</activeProfiles>

三、创建私有公库

1、创建普通的maven项目

在这里插入图片描述

2、修改项目的pom.xml

​ 在pom文件中加入distributionManagement节点,注意:pom.xml中repository里的id需要和.m2中setting.xml里的server id名称保持一致

    <!-- nexus 注意:id必须一致!-->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Nexus Release Repository</name>
            <url>http://10.18.1.21:8081/nexus/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://10.18.1.21:8081/nexus/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

3、发布私有公库

​ 执行部署命令即可发布。

mvn deploy

​ 登录Nexus,查看对应的仓库已经有相关的依赖包了

在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yohann*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值