nexus部署私库及上传和拉包处理

部署不在此赘述,部署好后地址为:http://ip:8081/nexus

默认账号和密码:用户名:admin 密码:admin123

nexus里可以配置3种类型的仓库,分别是proxy、hosted、group

proxy是远程仓库的代理。比如说在nexus中配置了一个central repository的proxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库下载,然后返回给用户,相当于起到一个中转的作用


hosted是宿主仓库,用户可以把自己的一些jar,deploy到hosted中,也可以手动上传jar到hosted里。比如说自己项目封装的包给其它项目使用


group是仓库组,将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址,只要统一配置group的地址即可

创建代理库

如下以创建华为云代理为例,

填入地址,其它不用管,点击创建即可

创建私有库

选择hosted有2种模式,Snapshot快照仓库和 Release发行仓库

Snapshot快照仓库用于保存开发过程中的不稳定版本,Release发行仓库则用来保存稳定的版本。

我们只需要处理上面2个重点位置即可

将Version policy选择为Snapshot;(如果你想创建的是发布版本则使用Release)

将Deployment policy选择Allow redeploy,允许部署和更新私服上的组件

然后保存即可

创建仓库组

对于创建组的策略模式选择mixed混合组

该组的成员选择我们需要放进来的仓库即可

推送项目模块包到私

在apache-maven-3.6.1\conf的settings.xml中的servers添加server

账号密码为nexus的账号密码,可以自己创建一个账号专门用来上传下载

这里的id对应下方pom文件提交私库的id

<server>
	<id>nexus</id>
	<username>admin</username>
	<password>admin123</password>
</server>

根项目的pom文件:

    <!--提交私库-->
    <distributionManagement>
        <repository>
            <id>nexus</id>
            <url>http://192.168.0.90:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus</id>
            <url>http://192.168.0.90:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

这里有2个库,具体采用哪个库就看我们的版本号后缀

版本号为1.0.0-SNAPSHOT,则会采用SNAPSHOT

版本号为1.0.0-RELEASES,则会采用RELEASES

然后点击maven deploy即可上传

如果报401失败可能是pom的问题,需要再次写入上面关于pom中nexus的内容,也有可能没按照上面创建库/组时未将Deployment policy选择Allow redeploy

从私库下包

tip:下包一般用的url为仓库组的url,因为仓库组一般组合了代理库和私有库,非常方便

1、项目范围控制

根目录pom中引入下列代码,但是注意id与下面setting中配置的server的id一致

tip:配置之后只会走这里的配置,如果私库只有某些定制的包,还需要在这里加aliyun或者huaweicloud的库,也可以创建仓库组,引入代理库和私有库即可。

<!-- 强制读取私有库-->
		<repositories>
			<repository> 
				<id>nexus</id> 
				<name>nexus-repository</name>
				<url>http://192.168.0.90:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases> 
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>

		<pluginRepositories> 
			<pluginRepository>
				<id>nexus</id>
				<name>nexus-pluginRepository</name>
				<url>http://192.168.0.90:8081/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
			</pluginRepository>
		</pluginRepositories>

在apache-maven-3.6.1\conf的settings.xml中的servers添加server

这里的id还是对应上面的pom文件的id

	<server>
		<id>nexus</id>
		<username>admin</username>
		<password>admin123</password>
	</server>

2、全局范围控制

这种所有依赖包直接找该库,要求该库存在代理库和私有库,这样依赖才能正常拉下来


  <servers>
	<server>
		<id>nexus</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
  </servers>

  <mirrors>
	<mirror>
		<id>nexus</id>
		<mirrorOf>*</mirrorOf>
		<url>http://192.168.0.90:8081/repository/maven-public/</url>
	</mirror>
  </mirrors>

  <profiles>
    	<profile> 
		<id>nexus</id>
		<repositories>
			<repository> 
				<id>nexus</id> 
				<name>nexus-repository</name>
				<url>http://192.168.0.90:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases> 
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>

		<pluginRepositories> 
			<pluginRepository>
				<id>nexus</id>
				<name>nexus-pluginRepository</name>
				<url>http://192.168.0.90:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases> 
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
		
	</profile>
  </profiles>
  
  <activeProfiles>
      <activeProfile>nexus</activeProfile>
  </activeProfiles>

3、匿名下包

默认情况下,如果在maven setting文件下不设置nexus的账号密码,拉取包会出现报错Not authorized,nexus中配置允许匿名访问服务器,只要勾上即可

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值