maven 教程五 将项目发布到私服

1 . 修改私服中仓库的部署策略


Release版本的项目应该发布到Releases仓库中,对应的,Snapshot版本应该发布到Snapshots仓库中。Maven根据pom.xml文件中版本号<version>节点的属性是否包含-SNAPSHOT,来判断该项目是否是snapshot版本。如果是snapshot版本,在执行mvn deploy部署命令时,maven会自动将项目发布到Snapshots仓库。要发布项目,首先需要将Releases仓库和Snapshots仓库的“Deployment Policy”设置为“Allow Redeploy”:




2 . 配置项目的部署仓库


在pom.xml中分别对Release版本和Snapshot版本配置部署仓库,其中id唯一,url分别对应私服中Releases和Snapshots仓库的Repository Path:




<uniqueVersion>表示是否为Snapshot版本分配一个包含时间戳的构建号,效果如下:


    <distributionManagement>
        <snapshotRepository>
            <id>user-snapshot</id>
            <name>User Porject Snapshot</name>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
        <repository>
            <id>user-release</id>
            <name>User Porject Release</name>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>
    </distributionManagement>


3 . 启用Deployment用户


Nexus默认有三个用户,其中Deployment用户用于部署项目:



Deployment用户默认密码为deployment123,右键菜单可修改或重置密码:



settings.xml中分别为上面配置的部署仓库配置server,其中id需要分别对应上面的部署仓库id:

    <servers>
        <server>
            <id>user-release</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>user-snapshot</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>

4 . 发布项目


右键pom.xml - Run As - 2 Maven build...


发布成功后,在私服的仓库中就能看到了:



5 . 在Nexus中手动上传项目构件


在Nexus仓库的Artifact Upload选项卡中,填写相关信息,可以手动的方式上传项目构件:




注:但是现在还是无法使用私服下载依赖,还需要配置如下内容在setting.xml 文件中:

  <profiles>    
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>


OK,现在一个私服就搭建成功了。

原文链接:Maven入门指南⑥:将项目发布到私服

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值