Nexus3 common function memo

About nexus3

Java developers often deploy nexus3 on the intranet for the following purposes:

  1. The cache of the central warehouse;
  2. Intranet private warehouse;

Next, combat these two functions separately;

Environmental information

  1. nexus3 version: 3.19.1
  2. maven version: 3.6.3
  3. JDK:1.8.0_191

nexus3 deployment

This article focuses on the use of nexus3, and does not discuss the details of deployment here. It is recommended to use docker to deploy. I am deploying it through docker on a home NAS. For details, please refer to "Qunhui DS218 + do maven private server (nexus3)"

New warehouse used as cache

The central warehouse here uses Alibaba Cloud, which has excellent speed and stability:

  1. The operation of creating a new warehouse is as follows:
    Insert picture description here
  2. Select maven2 (proxy) on the type selection page, as shown in the red box below:
    Insert picture description here
  3. Just fill in two places on the next page, the name: aliyun-proxy, remote storage: http://maven.aliyun.com/nexus/content/groups/public/, as shown in the red box below:
    Insert picture description here
  4. After submitting the form, return to the list page, click the copy button on the new warehouse to get the warehouse address, as shown below:
    Insert picture description here
  5. Write down the address of this warehouse ( http://192.168.50.43:8081/repository/aliyun-proxy/ ), all computers on the intranet can get the central warehouse jar package from this address, the setup method will be mentioned later;

Newly built warehouse used as private warehouse

For jars that are not in the central warehouse, as well as the two-party libraries released in the project, they can be stored in private warehouses;

  1. Create a new warehouse and select maven2 (hosted) as the type , as shown in the red box below:
    Insert picture description here
  2. Name: nexus-private , others do not need to be modified:
    Insert picture description here
  3. It should be noted here that if the private warehouse you create is used to save the self-released two-party library, it is best to build two, one to save the officially released version Policy type: Release, and the other to save the development (maven (Do not cache locally), Version policy type is Snapshot, this article only built a Release type for simplicity;
  4. Write down the address of this warehouse: http://192.168.50.43:8081/repository/nexus-private/
  5. So far, the warehouse has been created, we have the following two warehouses:
    cache type : http://192.168.50.43:8081/repository/aliyun-proxy/
    local private type : http://192.168.50.43:8081/repository/nexus -private /
  6. With the warehouse, next set up Maven on the development environment;

Maven settings (using cache repository)

First set up the aliyun-proxy warehouse so that you can use the cache function of nexus3:

  1. Open the maven configuration file settings.xml ;
  2. Find the mirrors node, add a server and configure, the content is as follows:
<mirror>
  <id>aliyun-proxy</id>
  <mirrorOf>*</mirrorOf>
  <url>http://192.168.50.43:8081/repository/aliyun-proxy/</url>
</mirror>
  1. The setting of the cache warehouse has been completed. Next, verify it by building a maven project. The following is the pom.xml file of the simplest maven project:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.bolingcavalry</groupId>
    <artifactId>nexus3demo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.28</version>
        </dependency>
    </dependencies>
</project>
  1. Execute the command in the directory where pom.xml is located: mvn clean compile -U -DskipTests , as shown below, it can be seen that the jar of the central warehouse is downloaded through nexus3, and then the project is successfully built:
    Insert picture description here

Jar that does not exist in the central warehouse

An important function of the private warehouse is to provide jar downloads outside the central warehouse. Let's take an example:

  1. Add a jar that does not exist in the central repository in pom.xml:
<dependency>
  <groupId>io.confluent</groupId>
  <artifactId>kafka-schema-registry-client</artifactId>
  <version>3.3.1</version>
</dependency>
  1. If you go to build, you will get an error: The
    3.
    above problems are common. Some jars are not released to the central warehouse. If you can't find them when building with maven, you will get an error.

Upload jar to private warehouse

The solution to the above problem: find this jar-> upload to private warehouse-> download this jar from private warehouse when maven is built;

  1. With the idea in mind, let's try to solve the above problem with a private warehouse;
  2. Download the above jar to the local, download address: http://packages.confluent.io/maven/io/confluent/kafka-schema-registry-client/3.3.1/kafka-schema-registry-client-3.3.1. jar
  3. Log in to nexus3 and follow the steps below:
    Insert picture description here
  4. Fill in the form and follow the steps in the figure below to submit the jar file to nexus3:
    Insert picture description here
  5. Now that there is a jar in the private warehouse, let's see how maven uses this jar file;

maven uses private repositories

  1. Open the maven configuration file settings.xml;
  2. Find the profiles node and add a profile configuration as follows:
    Insert picture description here
  3. Find the activeProfiles node, add an activeProfile and configure, the content is as follows:
<activeProfile>nexus3</activeProfile>
  1. Find the newly added mirror and modify the value of its mirrorOf node. The modified mirror node value is as follows:
<mirror>
  <id>aliyun-proxy</id>
  <mirrorOf>external:local-nexus3</mirrorOf>
  <url>http://192.168.50.43:8081/repository/aliyun-proxy/</url>
</mirror>
  1. The value of mirrorOf is changed from the previous * to external: local-nexus3 , which is the exclusion operation of the forwarding logic. After doing this, the request of the local-nexus3 warehouse will be forwarded to the private warehouse, and all other requests are forwarded to the cache Warehouse aliyun-proxy ;
  2. Build the maven project just now, and finally build it successfully this time, as shown below, the data related to kafka-schema-registry-client are downloaded from the private warehouse:
    Insert picture description here
    so far, the common cache and private warehouse functions of nexus3 have been tried, if you We are building a private maven repository, hope this article can provide you with a reference.

Welcome to pay attention to my public number: programmer Xinchen

Insert picture description here

Published 376 original articles · praised 986 · 1.28 million views

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/105458882