Maven发布项目到私服

秒速五厘米 2022-08-07 00:23 284阅读 0赞
  1. 首先在项目的pom.xm文件中配置:
  2. <distributionManagement>
  3. <repository>
  4. <id>releases</id>
  5. <name>releases repo</name>
  6. <url>http://localhost:8081/nexus/content/repositories/releases/</url>
  7. </repository>
  8. <snapshotRepository>
  9. <id>snapshots</id>
  10. <name>snapshots repo</name>
  11. <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
  12. </snapshotRepository>

通过右击pom.xml—->run as—->run configurations在goals中输入 clean deploy 发布项目,在maven控制台会报这样的一个错误: Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1][ERROR] 这是是因为我们还没有获得发布项目到私服上的权限,需要在settings.xml中的servers节点下配置:

  1. <server>
  2. <id>releases</id> //指向repository的id
  3. <username>deployment</username>
  4. <password>deployment123</password>
  5. </server>
  6. <server>
  7. <id>snapshots</id>
  8. <username>deployment</username>
  9. <password>deployment123</password>
  10. </server>

此时我们就可以看到snapshots仓库中发布的项目.

有时候一个公司可能同时开发几个不同的项目,这个时候我们希望将不同的项目发布到不同的仓库中,并且对于每一个项目只能有该项目的开发人员发布项目到指定的仓库中去,在这个时候我们就需要通过基于角色的权限管理来实现,例如有role1、role2两个不同的角色可以是实现不同的操作,我们通过将role1分配给用户user1、user2,将role2分配给用户user3,user4,这样不同的用户就具有不同的权限。

Center

选择hosted Repository

Center 1

再次选择hosted Repository,创建snapshot类型的仓库

接下来选择security下的privileges,然后点击add按钮选择Repository Target Privilege,来配置允许对仓库进行的操作

Center 2

Center 3

Center 4

接下来创建角色:

选择security下的roles ,同样单击add 选择nexus role

Center 5

接下来创建用户并且分配角色:

选择security下的users ,同样单击add 选择nexus user

Center 6

此时在项目的pom.xml中配置:



releases
releases repo
http://localhost:8081/nexus/content/repositories/myReleases/


snapshots
snapshots repo
http://localhost:8081/nexus/content/repositories/mySnapshots/

在settings.xml中配置:

  1. <server>
  2. <id>releases</id>
  3. <username>nexus</username>
  4. <password>nexus123</password>
  5. </server>
  6. <server>
  7. <id>snapshots</id>
  8. <username>nexus</username>
  9. <password>nexus123</password>
  10. </server>

项目就可以发布成功。

发表评论

表情:
评论列表 (有 0 条评论,284人围观)

还没有评论,来说两句吧...

相关阅读