Detailed explanation of maven configuration nexus private server

Introduction:

The premise is that the private server has been set up. We need to configure relevant parameters in local maven and connect the private server as a warehouse;

Configuration steps

1. Local maven settings.xml configuration

1.1 Configure the local warehouse location

Local warehouse configuration, it is recommended to configure it in the .m2 folder

 <localRepository>C:\Users\lele\.m2\repository</localRepository>

Insert image description here

1.2 server configuration

Mainly configure the account password separately for the ID used;
the name of this ID tag can be customized and unique, which will be used in the following steps.

  <servers>
    <!-- 设置maven-releases的账号密码(id与项目POM中的distributionManagement元素id必须一样) -->
    <server> 
    <id>maven-releases</id> 
    <username>your-username</username> 
    <password>your-password</password> 
    </server> 
  <!-- 设置maven-snapshots的账号密码(id与项目POM中的distributionManagement元素id必须一样) -->
    <server> 
    <id>maven-snapshots</id> 
    <username>your-username</username> 
    <password>your-password</password> 
    </server>  
  <!-- 设置maven-central的账号密码 -->
    <server> 
    <id>maven-public</id> 
    <username>your-username</username> 
    <password>your-password</password> 
    </server> 
  </servers>
  

1.3 Mirror configuration

<id>标签: It must be consistent with the configuration in the previous step label; in this way, you can get the account and password to connect to the image;

<name>标签: Name customization
<url>标签: The address of maven-public in the private server
<mirrorOf>标签: designated as central

  <mirrors>
    <!-- 镜像配置 -->
    <mirror>
      <id>maven-public</id>
      <name>maven-public</name> 
      <url>http://ip:host/repository/maven-public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

Insert image description here

1.4 Private server warehouse configuration

<profiles>
  <profile>
    <!-- 私服id -->
    <id>Nexus</id>
       <repositories>
         <repository>
          <id>maven-public</id>
          <url>http://ip:host/repository/maven-public/</url>
            <snapshots><enabled>true</enabled></snapshots>
            <releases><enabled>true</enabled></releases>
         </repository>
       </repositories>
             <!--指定插件下载地址-->
      <pluginRepositories>
        <pluginRepository>
            <id>maven-public</id>
            <url>http://ip:host/repository/maven-public/</url>
            <snapshots><enabled>true</enabled></snapshots>
            <releases><enabled>true</enabled></releases>
        </pluginRepository>
      </pluginRepositories>   
     </profile>
  </profiles>
 <!--启动私服仓库 -->
  <activeProfiles>
    <activeProfile>Nexus</activeProfile>
  </activeProfiles>

Insert image description here

2. maven project pom.xml configuration

Automatically submit the jar to the private server.
The id added to the pom.xml file must be consistent with the configuration in setting.xml.

    <!--私服配置-->
    <distributionManagement>
        <repository>
            <id>maven-releases</id>
            <url>http://ip:host/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <url>http://ip:host/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

Insert image description here

Running mvn deploy will submit the jar to the private server warehouse.

Complete configuration template

<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
 
  <!--配置本地仓库地址-->
  <localRepository>C:\Users\lele\.m2\repository</localRepository>

  
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>

  </proxies>
<!--配置账号-->
  <servers>
   <!-- 设置maven-releases的账号密码(id与项目POM中的distributionManagement元素id必须一样) -->
    <server> 
    <id>maven-releases</id> 
    <username>your-username</username> 
    <password>your_password</password> 
    </server> 
  <!-- 设置maven-snapshots的账号密码(id与项目POM中的distributionManagement元素id必须一样) -->
    <server> 
    <id>maven-snapshots</id> 
    <username>your-username</username> 
    <password>your_password</password> 
    </server>  
  <!-- 设置maven-public的账号密码 -->
    <server> 
    <id>maven-public</id> 
    <username>your-username</username> 
    <password>your_password</password> 
    </server> 
  </servers>
  
  <mirrors>
    <!-- 私服镜像配置 -->
    <mirror>
      <id>maven-public</id>
      <name>maven-public</name> 
      <url>http://ip:host/repository/maven-public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

<profiles>
  <profile>
    <!-- 私服id -->
    <id>Nexus</id>
      <!--指定仓库下载地址-->
      <repositories>
         <repository>
            <id>maven-public</id>
            <url>http://ip:host/repository/maven-public/</url>
            <snapshots><enabled>true</enabled></snapshots>
            <releases><enabled>true</enabled></releases>
         </repository>
      </repositories>

      <!--指定插件下载地址-->
      <pluginRepositories>
        <pluginRepository>
            <id>maven-public</id>
            <url>http://ip:host/repository/maven-public/</url>
            <snapshots><enabled>true</enabled></snapshots>
            <releases><enabled>true</enabled></releases>
        </pluginRepository>
      </pluginRepositories>      
  </profile>
</profiles>
<!--激活环境配置-->
  <activeProfiles>
    <activeProfile>Nexus</activeProfile>
  </activeProfiles>
</settings>

maven tags and detailed explanation

maven packages the source code package and jar together and uploads them to the private server

Guess you like

Origin blog.csdn.net/weixin_43811057/article/details/132720550