Introduction and use of Maven private server (Nexus)

Private server installation

https://blog.csdn.net/javanbme/article/details/113336338

 

1. Warehouse Introduction

1) maven-central: maven central library, pull the jar from https://repo1.maven.org/maven2/ by default

2) maven-releases: private library release jar

3) maven-snapshots: private library snapshot (debug version) jar

4) maven-public: warehouse grouping, combining the above three warehouses to provide external services, and use them in the local maven basic configuration settings.xml.

 

Nexus warehouse type introduction

The following warehouses are installed by default. You can also modify the addresses of remote warehouses, third-party warehouses, etc. in the console.

  • hosted (host warehouse library): store the jar package (official version, test version) developed by the company
  • proxy (proxy warehouse): proxy central warehouse, jar package of test version under Apache
  • group (group warehouse): connect to the group warehouse when in use, including Hosted (host warehouse) and Proxy (proxy warehouse)

The process of finding dependent packages: First find in the local warehouse, if it misses, then find the remote private server; the search rule of the remote private server is also to find the private library of the host attribute first, and then find the remote warehouse of the proxy attribute; it can be configured Multiple proxy;

 

2. Warehouse introduction and creation

2.1 Create jCenter Alibaba Cloud Warehouse

http://maven.aliyun.com/nexus/content/groups/public/

2.2 maven central warehouse (no need to modify)

https://repo1.maven.org/maven2/

2.3 Move the Jcenter warehouse to the maven-public group warehouse

 

3. Configuration dependencies

3.1 Add maven repository mirror

After creating the group warehouse, modify the setting.xml file and add the maven warehouse mirror, as follows

<mirrors>
    <mirror>
      <id>nexus-myself</id>
      <!--*指的是访问任何仓库都使用我们的私服-->
      <mirrorOf>*</mirrorOf>
      <name>Nexus myself</name>
      <url>http://121.4.207.231:8081/repository/maven-public/</url>
    </mirror>
</mirrors>

3.2 Global configuration download dependency (that is, the project pom does not need to be configured)

Configure the private server configuration in the maven setting.xml file. After this configuration, all pom files of the maven project that use this configuration locally do not need to configure the private server to download the relevant configuration.

<profiles>
  <profile>
     <id>mycof</id>
        <repositories>
        <!-- 私有库地址-->
          <repository>
          <id>nexus</id>
          <url>http://121.4.207.231:8081/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>      
      <pluginRepositories>
        <!--插件库地址-->
        <pluginRepository>
          <id>nexus</id>
          <url>http://121.4.207.231:8081/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
           </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
</profiles>

3.3 Activate the use of the above configuration

<!--激活profile-->
<activeProfiles>
  <activeProfile>mycof</activeProfile>
</activeProfiles>

3.4 Separate project download dependency (that is, configuration in the project pom file) (extended)

This configuration is to modify the pom file of a single project without modifying the setting configuration of maven

<repositories>
  <repository>
    <id>nexus</id>
    <url>http://121.4.207.231:8081/repository/maven-public/</url>
    <releases>
      <enabled>true</enabled>
    </releases>
    <snapshots>
    <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>

 

4. Upload Jar package to private server

For jar packages that are not available in the central warehouse, we need to publish the jar packages to the private server by ourselves. The jar packages are mainly divided into two categories.

One type is developed locally for use by the rest of the project team. This directly configures the project’s pom file and maven setting file, and then deploys it to be released;

The other is a third-party jar package, which can be uploaded directly on the web page and set the corresponding GAV;

 

4.1 Project upload configuration developed by local maven

Maven's setting file configuration

<servers>
    <server>  
        <id>maven-releases</id>  
        <username>admin</username>  
        <password>admin123</password>  
    </server>  
    <server>  
        <id>maven-snapshots</id>  
        <username>admin</username>  
        <password>admin123</password>  
    </server>
  </servers>

Pom file configuration in the project

<distributionManagement>
    <repository>
        <id>maven-releases</id>
        <name>Nexus Release Repository</name>
        <url>http://121.4.207.231:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>maven-snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://121.4.207.231:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

<profiles>
    <profile>
        <id>java8-doclint-disabled</id>
        <activation>
            <jdk>1.8</jdk>
        </activation>
        <properties>
            <javadoc.opts>-Xdoclint:none</javadoc.opts>
        </properties>
    </profile>
</profiles>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <!--编译插件-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
                <!--解决JDK7以后,带com.sun.*的类库将不会被支持-->
                <!--<compilerArgument>-XDignore.symbol.file</compilerArgument>-->
                <compilerArguments>
                    <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>
                </compilerArguments>
            </configuration>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
        </plugin>
        <!-- 生成javadoc文档包的插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9</version>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <additionalparam>${javadoc.opts}</additionalparam>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!-- 生成sources源码包的插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!--部署jar包到远程仓库-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.7</version>
        </plugin>
    </plugins>
</build>

  Execute maven's deploy command

  ps: The first initialization is a bit slow and patiently wait for the deploy to succeed and check the dependencies

  The Release warehouse does not support repeated releases by default. If the SNAPSHOT suffix is ​​used in the project, no configuration is required. The snapshot version will detect the new snapshot version based on the upload time.

 

4.2 Upload of a third-party jar package

image.png

 

5. Introduce the private server Jar package

 

 

 

Guess you like

Origin blog.csdn.net/javanbme/article/details/113345312