maven私服仓库搭建、上传或者拉取jar包

maven私服仓库搭建

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

一、使用Docker安装Nexus

docker pull sonatype/nexus3
mkdir -p /data/nexus-data
chown -R 200 /data/nexus-data
docker run -tid -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus -v /data/nexus-data:/nexus-data sonatype/nexus3

二、登录Nexus进行配置

访问:http://ip:8081/nexus

第一次登录会有提示,密码在/data/nexus-data/admin.password文件中,登陆后修改为自己的密码

第一步

增加新的代理源

img

第二步

选择添加maven2的代理

img

第三步

添加代理

name:aliyun

url代理地址:http://maven.aliyun.com/nexus/content/groups/public

img

Cache统一设置为200天 288000

img

第四步

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

img

第五步

设置私用仓库可重复发布

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

img

三、Maven配置

    <!-- 配置nexus的账号密码 -->
  <servers>
    <server>
      <id>releases</id>
      <username>admin</username>
      <password>yangfan</password>
    </server>
    
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>yangfan</password>
    </server>
  </servers>
</settings>

四、发布到私有仓库

项目pom.xml配置添加

<distributionManagement>
    <repository>
        <id>releases</id>
        <name>Nexus Release Repository</name>
        <url>http://ip:8081/nexus/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://ip:8081/nexus/repository/maven-snapshots</url>
    </snapshotRepository>
</distributionManagement>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

如果项目有子模块,子模块的pom.xml中添加

<build>
     <plugins>
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
         </plugin>
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-source-plugin</artifactId>
         </plugin>
     </plugins>
</build>

五、从私服拉取jar包

需要拉取jar包的项目中,pom.xml添加

 <!--代理仓库-->
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Reposotory</name>
            <url>http://192.168.1.113:8081/nexus/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

maven配置添加私服的镜像地址,settings.xml

<id>nexus</id>
	<mirrorOf>central</mirrorOf>
	<name>Nexus Reposotory</name>
	<url>http://192.168.1.113:8081/nexus/repository/maven-public/</url>
</mirror>
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

木一番

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

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

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

打赏作者

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

抵扣说明:

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

余额充值