Use Nexus to build Maven private library practice

This article quickly demonstrates how to build and use the Nexus local library, and the basic usage reference for Nexus:
Introduction to building a Maven private library with Nexus

Actual scene

The actual scene of this article is:

  • The local development machine can connect to the external network
  • The test or official deployment environment can only connect to the intranet
  • The project uses an in-house developed component library

Before building the Maven private library, the processing method is:

  1. Download dependencies, plugins, etc. on the local development machine
  2. Copy the directory of the local library to the test or deployment environment

That is to say, the way of using the local library, but there is a problem of inconvenient use in this way: to
add a new dependency in pom.xml, the entire directory needs to be copied again, because this dependency will download other dependencies , it is more troublesome to accurately know this dependency and its related dependencies, so copy the entire library directory. In general, the directory content of the local library is relatively large, and the unit is basically G, so it usually takes several hours to copy.

Nexus build plan

The required machines are as follows:

  • Machine A: A development machine that can connect to the external network. There is Maven's local library directory here
  • Machine B: Deployment machine, only connected to intranet
  • Machine C: Nexus server, only connected to intranet

Considering that the machine where Nexus is located cannot connect to the external network, the plan is as follows:

  • Publish the stable version library developed by yourself to maven-releases
  • Create a library maven-local for batch importing dependencies in the local library of machine A
  • The maven-public configuration contains maven-releases and maven-local

Nexus build steps

1. Create a library maven-local to store the dependencies in the local library of machine A

The role of maven-local is to import the dependencies downloaded from the original local library into nexus. Before creating the library, you need to create a Blob Store to store files. The creation steps are as follows:

  1. Log in to the Nexus server, click Create Blob Store
    insert image description here

  2. After selecting the storage type Fil, enter the name of the Blob Store, and the path will be automatically generated according to the name.
    insert image description here

Note: The default storage path is located in sonatype-work\nexus3\blobs directory.

  1. After the creation is complete, you can see the Blob Store in the storage list

insert image description here

  1. Click "Create repository"

insert image description here

  1. Select maven2 (hosted)

insert image description here

  1. Enter the name of the library, select Blob Store, and select the deployment strategy to allow redeployment
    insert image description here

  2. After the input is complete, click "Create repository" to complete the creation. After creation, you can see it in the repository list

insert image description here

2. Batch import dependencies of local libraries

Import all dependencies under the local library path of machine A to the Nexus service of machine C. Proceed as follows:

  1. Go to https://download.csdn.net/download/oscar999/87961368 to download the script for batch importing the maven local library directory to the Nexus private server. The downloaded script name is mvnimport.sh
  2. Copy mvnimport.sh to the local library root path of machine A
    3 Git Bash switch to the local library path and execute the command../mvnimport.sh -u admin -p yourpassword -r http://机器C:8081/repository/maven-local/

For more details about batch import, please refer to: How Nexus imports jars and batch imports Maven's local library directory

Publish the stable version library developed by yourself to maven-releases

In the own library developed by machine A, the stable version is released to maven-releases, and the version in the development process is released to maven-snapshots.
For how to publish the library developed by yourself, you can refer to: How to publish the project to the Nexus private server in Maven



Guess you like

Origin blog.csdn.net/oscar999/article/details/131466465