nexus

nexus流程:如果构建的 Maven 项目本地仓库没有对应的依赖包,那么就会去 Nexus 私服去下载, 如果Nexus私服也没有此依赖包,就去远程中央仓库(即proxy代理仓库,默认是maven中央仓库,可设置其他的镜像)下载依赖。 Nexus 私服下载成功后再下载至本地 Maven 库供项目引用。 

Nexus 是通过仓库组统一管理多个仓库,我们在项目中可直接通过请求仓库组来请求到 被仓库组管理的多个仓库。如:通过http://192.168.10.10:8081/nexus/content/groups/public/ 这个地址

可以请求到下面的仓库如:http://192.168.10.10:8081/nexus/content/repositories/snapshots/等


hosted 宿主仓库:主要用于发布内部项目构件或第三方的项目构件(如购买商业的)以及无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)。宿主仓库是我们经常用到的,本地发布就是发布到这些宿主仓库中的其中一个。

releases:内部的模块中 release 模块的发布仓库。
snapshots:发布内部的 SNAPSHOT 模块的仓库。
3rd party:第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去。

proxy代理仓库:代理公共的远程仓库,可以通过这个修改默认的仓库,默认的中央仓库是https://repo1.maven.org/maven2/,可以在这里改为阿里云的代理。

下载中央仓库的索引:如下改为true


添加代理仓库:



然后保存,放在central上边即可。


索引下载完成后即可看到:



maven配置:

maven本地库连接私有库,私有库代理连接阿里云的镜像仓库。

settings.xml:

<servers>
    <server>
	<!--连接仓库的id,之后pom中发布id要和此处一致-->
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
	</server>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
</servers>
 <!--使用私服的配置-->
  <profiles>
     <profile>
		 <id>test</id>
		 <repositories>
			 <repository>
				 <id>nexus</id>
				 <url>http://192.168.10.10:8081/nexus/content/groups/public/</url>
				 <releases><enabled>true</enabled></releases>
			 	 <snapshots><enabled>true</enabled></snapshots>
			 </repository>
		 </repositories>
		 <pluginRepositories>
			 <pluginRepository>
				 <id>nexus</id>
				 <url>http://192.168.10.10:8081/nexus/content/groups/public/</url>
				 <releases><enabled>true</enabled></releases>
				 <snapshots><enabled>true</enabled></snapshots>
			 </pluginRepository>
		 </pluginRepositories>
	 </profile>
  </profiles>

激活私服,激活的名字和上面私服的配置的id一致。

<!--激活私服-->
  <activeProfiles>
	<activeProfile>test</activeProfile>
  </activeProfiles> 


pom中:这是在pom部署时连接用,id就是上面定义的server的id。且必须一致,不然连不上。这个配置一般放到顶级parent中。

<!-- 设定团队持续集成发布包服务器 -->
<distributionManagement>
	<repository>
		<id>nexus-releases</id>
		<url>http://${maven.local.server}/content/repositories/releases</url>
	</repository>
	<snapshotRepository>
		<id>nexus-snapshots</id>
		<url>http://${maven.local.server}/content/repositories/snapshots</url>
		<uniqueVersion>false</uniqueVersion>
	</snapshotRepository>
</distributionManagement>

然后depoly即可发布到私服了。

具体是发布到nexus-releases还是nexus-snapshots,根据要发布的包的pom文件中定义的版本version,版本中是SNAPSHOT(如:0.0.1-SNAPSHOT)就发布到snapshots中,且只能叫SNAPSHOT,其他的名字就发布到releases中了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值