Maven发布项目到私服

          首先在项目的pom.xm文件中配置:

     <distributionManagement>
      <repository>
          <id>releases</id>
          <name>releases repo</name>
          <url>http://localhost:8081/nexus/content/repositories/releases/</url>
      </repository>
      <snapshotRepository>
        <id>snapshots</id>      
        <name>snapshots repo</name>
        <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
      </snapshotRepository>
  </distributionManagement>

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

       <server>
      <id>releases</id> //指向repository的id
      <username>deployment</username>
      <password>deployment123</password>
    </server>    
     <server>
      <id>snapshots</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>    

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


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

   

  选择hosted Repository



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

 

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






接下来创建角色:

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

  

  

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

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




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

  <distributionManagement>
      <repository>
          <id>releases</id>
          <name>releases repo</name>
          <url>http://localhost:8081/nexus/content/repositories/myReleases/</url>
      </repository>
      <snapshotRepository>
        <id>snapshots</id>      
        <name>snapshots repo</name>
        <url>http://localhost:8081/nexus/content/repositories/mySnapshots/</url>
      </snapshotRepository>
  </distributionManagement>



在settings.xml中配置:

     <server>
      <id>releases</id>
      <username>nexus</username>
      <password>nexus123</password>
    </server>    
     <server>
      <id>snapshots</id>
      <username>nexus</username>
      <password>nexus123</password>
    </server>    
  </servers>

项目就可以发布成功。



 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值