Nexus和Maven安装配置

1、下载安装Maven

wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz

配置MAVEN_HOME

vi /home/jenkins/.bash_profile

MAVEN_HOME=/usr/local/jenkins/apache-maven-3.5.0

export PATH=$PATH:$MAVEN_HOME/bin

2、下载Nexus

http://www.sonatype.org/nexus/archived/#step2top

wget http://download.sonatype.com/nexus/oss/nexus-2.14.4-03-bundle.tar.gz

tar -zxvf nexus-2.14.4-03-bundle.tar.gz

启动:/usr/local/jenkins/nexus-2.12/bin/nexusstart

关闭:/usr/local/jenkins/nexus-2.12/bin/nexusstop

访问:http://192.168.1.135:8081/nexus

默认端口8081,默认用户/密码:admin/admin123

3、配置Nexus

将列表中所有Type为proxy 的项目的 Configuration 中的 Download Remote Indexes 设置为True

Nexus和Maven安装配置

将Releases仓库的Deployment Policy设置为 AllowReDeploy 

Nexus和Maven安装配置

当然我们也避免不了会使用到一些第三方的 jar ,而这些jar包也不存在于互联网上的maven中央仓库中,这时我们可以手工添加jar 到我们的私服中。 
添加第三方 jar 如下: 

Nexus和Maven安装配置

写完必选字段,点击Upload Artifact(s)按钮即可。

如果需要删除的话,如下: 

Nexus和Maven安装配置

 

4、使用私服配置

配置发布jar到自己的私服

修改Maven的配置文件settings.xml

<servers>

    <server>

        <id>releases</id>

       <username>admin</username>

       <password>admin123</password>

    </server>

    <server>

       <id>snapshots</id>

       <username>admin</username>

       <password>admin123</password>

    </server>

</servers>

修改工程的pom.xml中添加

<distributionManagement>

                  <repository>

                           <!--这个ID需要与你的release仓库的settings.xml Repository ID一致 -->

                           <id>releases</id>

                           <url>http://192.168.1.135:8081/nexus/content/repositories/releases</url>

                  </repository>

                  <snapshotRepository>

                           <!--这个ID需要与你的snapshots仓库的settings.xml Repository ID一致 -->

                           <id>snapshots</id>

                           <url>http://192.168.1.135:8081/nexus/content/repositories/snapshots</url>

                  </snapshotRepository>

</distributionManagement>

 

配置使用私有maven库(即自己的私服http://192.168.1.135:8081/nexus/

在项目的pom.xml中配置Nexus私服,这样的配置只对当前的Maven项目有效。

<!--配置jar包使用私有maven-->

<repositories>

      <repository>

          <id>public</id>

          <name>Team MavenRepository</name>

          <url>http://172.18.19.157:8081/nexus/content/groups/public/</url>

          <releases>

              <enabled>true</enabled>

          </releases>

          <snapshots>

             <enabled>true</enabled>

          </snapshots>

      </repository>

  </repositories>

<!--配置插件使用私有maven-->

<pluginRepositories> 

        <pluginRepository> 

            <id>nexus</id> 

            <name>nexus</name> 

           <url>http://172.18.19.157:8081/nexus/content/groups/public/</url> 

            <releases> 

               <enabled>true</enabled> 

            </releases> 

            <snapshots> 

                <enabled>true</enabled> 

            </snapshots> 

        </pluginRepository> 

</pluginRepositories> 

在Maven的settings.xml中配置profile元素,这样就能让本机所有的Maven项目都使用自己的Maven私服。

<profiles>

    <profile>

       <id>dev</id>

        <repositories>

            <repository>

                <id>local-nexus</id>

                <url>http://192.168.1.135:8081/nexus/content/groups/public/</url>

               <releases>

                   <enabled>true</enabled>

               </releases>

                <snapshots>

                   <enabled>true</enabled>

               </snapshots>

           </repository>

        </repositories>

<pluginRepositories>

       <pluginRepository>

                <id>local-nexus</id>

         <url>http://192.168.1.135:8081/nexus/content/groups/public/</url>

                <releases>

                                  <enabled>true</enabled>

                </releases>

                <snapshots>

              <enabled>true</enabled>

                </snapshots>

       </pluginRepository>

</pluginRepositories>

    </profile>

</profiles>

   <activeProfiles>

        <activeProfile>dev</activeProfile>

 </activeProfiles>

Nexus和Maven安装配置