nexus私服的使用+项目的发布

nexus的安装

  • 下载nexus 地址:http://download.csdn.net/detail/javamrzhang/9907629
  • 将G:\DevelopmentTools\nexus-2.0.3-bundle\nexus-2.0.3\bin 该路径配置到环境变量中,(此路径要参照你下载后放置的路径)
  • 打开文件”G:\DevelopmentTools\nexus-2.0.3-bundle\nexus-2.0.3\bin\jsw\conf\wrapper.conf” 将此处wrapper.java.command的值设置为G:\DevelopmentTools\jdk1.7\bin\java (java的环境变量)
  • 打开控制面板 执行nexus install (安装服务)
  • 执行 nexus start (启动服务)
  • 进行访问 http://127.0.0.1:8081/nexus (nexus默认的用户名:admin 密码:admin123)

项目私有仓库的配置

  • 项目的pom.xml文件中配置私有仓库的路径
<!-- 仓库的地址的配置 ,id name 都要唯一,后续maven的setting.xml 文件中有用到-->
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled><!-- 指定releases版本的可以用 -->
            </releases>
            <snapshots>
                <enabled>true</enabled><!-- 指定snapshots版本的可以用 -->
            </snapshots>
        </repository>
</repositories>

至此,该项目会直接到私服中去下载你指定的依赖库。

  • 如果我们搭建多个项目,却在pom文件中指定了不同的 repository,又想要让它们私服中去下载呢?先看它们各自的repository
<!--项目一-->
<repository>
            <id>h1</id>
            <name>h1 Repository</name>
            <url>http://xxxxxxx</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
</repository>
<!--项目二-->
<repository>
            <id>h2</id>
            <name>h2 Repository</name>
            <url>http://xxxxxxx</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
</repository>
  • 解决这个的办法就是直接配置 maven 中的 setting.xml 文件的 镜像地址,将其指向中央仓库地址
    在mirrors 节点中加入该子节点
 <!--mirrorOf 其实指其实是repository节点中的id节点的文本值 h1,h2,nexus3等等, 这边直接用*表示全部匹配-->
<mirror>
      <id>central</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
</mirror>
  • 此外这边还要注意一点,就是该镜像并无指明从仓库是否可以下载snapshot版本或releases版本。所以还需在profiles 节点中加入如下配置
<profile>
      <repositories>
        <repository>
          <id>central</id>
          <name>Repository for JDK 1.4 builds</name>
          <!--配置了镜像之后这个就没有URL意义了-->
          <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
          <layout>default</layout>
          <!--此处就是进行指明了可下载什么版本的-->
          <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
      </repositories>
 </profile>
  • 至此所有的配置已经完成了。 记住maven中的setting.xml 是全局文件,也就是说只要setting.xm文件配置了,那么所有项目的pom.xml文件都是参照此文件的配置。

发布项目到私服

  • 在项目pom.xml加入如下配置
<!--此处指明是snapshot版本发布的位置-->
<distributionManagement>
    <snapshotRepository>
            <id>snapshot</id><!--在setting.xml配置文件中需要用到,需唯一-->
            <name>snapsho project</name>
            <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
<distributionManagement>
<!--此处指明了release版本发布的位置-->
<distributionManagement>
     <repository>
            <id>release</id><!--在setting.xml配置文件中需要用到,需唯一-->
            <name>Releases Project</name>
            <url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
    </repository>
<distributionManagement>
  • 这里需要注意如果是snapshot版本的话pom.xml 中 version节点的必须为 0.0.1-SNAPSHOT
    相反release版本的话,当然就是 0.0.1-release不能是0.0.1-SNAPSHOT ,不然发布会不成功。
  • 在setting.xml 的servers节点中配置发布时需要的账号和密码
<server>
      <id>snapshot</id>
      <username>deployment</username><!--这里的账号和密码都可以在nexus中进行设置--->
      <password>deployment123</password>
    </server>
    <server>
      <id>release</id>
      <username>deployment</username><!--这里的账号和密码都可以在nexus中进行设置--->
      <password>deployment123</password>
 </server>
  • 此外还需要在nexus中对各个仓库中的Access Settings 项进行指定项目发布权限的配置。
    这里写图片描述

猜你喜欢

转载自blog.csdn.net/JavaMrZhang/article/details/75808294