nexus私服主要是在项目和maven中央仓库中间做代理,一般在公司内网或者公司内部的一些私包,都需要这么个产品。下面主要是关于maven和nexus之间的一些配置

1、在pom中配置nexus私服

<!-- jar仓库 -->
    <repositories>
        <repository>
            <id>nexus</id>
            <name>nexusRep</name>
            <url>http://xxx.74.97.19999:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <!-- 插件库 -->
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>nexusPlugin</name>
            <url>http://xxx.74.97.19999:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.

 

<profile>  
    <id>jdk18</id>  
    <activation>  
        <activeByDefault>true</activeByDefault>  
        <jdk>1.8</jdk>  
    </activation>  
    <properties>  
        <maven.compiler.source>1.8</maven.compiler.source>  
        <maven.compiler.target>1.8</maven.compiler.target>  
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
    </properties>   
</profile>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

 

 

2、在当前项目的pom文件做以上配置,仅仅在当前项目中生效,如果想在所有项目中生效,需要在maven的setting.xml文件中进行配置。

<profile>
      <id>nexusProfile</id>
      <activation>
        <jdk>1.8</jdk>
      </activation>
      <repositories>
        <repository>
            <id>nexus</id>
            <name>nexusRep</name>
            <url>http://xxx.74.97.19999:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
         </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>nexusPlugin</name>
            <url>http://xxx.74.97.19999:8081/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.

 

<activeProfiles>
  <activeProfile>nexusProfile</activeProfile>
</activeProfiles>
  • 1.
  • 2.
  • 3.

激活当前配置。

这样就可以使所有的项目都使用自己的nexus私服。但是你会发现还有小部分请求会到maven的中央工厂,解决方法就是配置mirror

<mirror>
    <id>nexus</id>
    <name>nexus</name>
    <mirrorOf>*</mirrorOf>
    <url>http://xxx.74.97.19999:8081/nexus/content/groups/public/</url>
</mirror>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.

这样限制住服务只能通过nexus私服去访问maven中央仓库,如果当前的nexus私服宕机了,那么项目是无法使用maven中央仓库数据的。

3、将项目发送到nexus私服中去

首先在pom中配置发布的地址

<distributionManagement>
        <repository>
            <id>nexus-rep</id>
            <name>nexusRep</name>
            <url>http://xxx.74.97.xxx:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snap</id>
            <name>nexusSnap</name>
            <url>http://xxx.74.97.xxx:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

 

发布项目还需要授权,这个需要在setting文件中配置

<server>
      <id>nexus-rep</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
    <server>
      <id>nexus-snap</id>
      <username>deployment</username>
      <password>deployment123</password>
</server>
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

 

 

执行mvn:deploy,即可发布。