This is the second day of my participation in the August Text Challenge.More challenges in August

We came to this world because we had to; In the end, we leave this world because we have to. ———— Yu Hua, To Live

Summary of a.

This article introduces the common configuration of the Nexus and practices how to push local code to the private server.

Basic configuration and use of Nexus

1. Nexus Configuration description

Click on the left Repositories button to see the repository contents as shown below:

Warehouse Description:

The Name column

  • Maven – central: maven ZhongYangKu, default from https://repo1.maven.org/maven2/ pull the jar.

  • Maven-releases: Releases the PRIVATE library JAR.

  • Maven-snapshots: snapshots of private libraries (debug versions) JAR.

  • Maven-public: repository group, which combines the preceding three repositories to provide external services. Maven-public is used in the local Maven basic configuration settings.xml.

The Type column (the default Nexus repository Type is the following four) :

  • Group (warehouse group type) : also known as group warehouse, used to make it easy for developers to select and set the order of the warehouses themselves;

  • Hosted (Hosted type) : The release repository for an internal project (where internal developers release JAR packages);

  • Proxy (proxy type) : searches for data from the Remote central warehouse (you can click the Configuration TAB of the corresponding warehouse, where the value of Remote Storage Location property is the path of the proxy Remote warehouse);

  • Virtual (virtual type) : virtual warehouse (this is basically not needed, focus on the use of the above three warehouses);

2. Create a customized private repository

Custom release private libraries

Click Create Repository to Create a custom Release private repository, select Maven2 (Hosted), as shown below:

The custom warehouse configuration is as follows:

The main configurations are as follows:

“Name” : a user-defined Name. It must be unique. Usually, “XXX” and “XXX” snapshots “end in” xxx-release”

Version the policy:

  • Release is generally the JAR of the distribution
  • A Snapshot is usually a JAR of a Snapshot version
  • The Mixed hybrid

Deployment Policy: Allow redeploy

Keep the default Settings for other configurations.

Custom Snapshot private library

To create a snapshot private library, change the Name to xxx-snapshots and the Version policy to snapshot, as shown in the following figure:

Custom proxy repositories

Default from https://repo1.maven.org/maven2/ pull jar, due to the cause of the network often unable to download resources, so here are configured ali cloud maven agent warehouse.

Ali cloud maven warehouse proxy configuration: maven.aliyun.com/mvn/guide

Create a proxy repository:

The configuration content is shown as follows:

Configuration description:

Name: The Name of the warehouse must be unique. Aliyun-proxy is used here

Version policy :Release

Remote storage: Remote warehouse address, this configuration ali cloud maven warehouse address: https://maven.aliyun.com/repository/public

Customize the order of group repositories

You can use the default maven-public, or you can customize a maven2 (group) repository.

The configuration is shown as follows:

3. Create a Nexus user

Maven configuration nexus description

Click on the previously defined maven2 (group) to view its URL, as shown below:

1. Configure in settings. XML file (globally valid)

Open the Maven configuration file (typically in the Maven installation directory conf/settings.xml for Windows machines), add a mirror child node to the
TAB, and copy the address. Add the following to settings.xml:

  <servers>
    <! The id of the nexus must be the same as that of mirros to match the authentication.
    <server>
      <id>my-maven</id>
      <username>test</username>
      <password>maven123456</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>my-maven</id>
      <! If mirrorof is set to *, all requests will go to the MIRROR URL. If mirrorof is repositoryID, the build will go to maven's default central repository. -->
      <mirrorOf>*</mirrorOf>
      <name>Custom private warehouse</name>
      <url>http://localhost:8081/repository/my-group/</url>
    </mirror>
  </mirrors>
Copy the code

After the configuration is complete, you can specify the settings. XML file in idea, as shown below:

After specifying the configuration file, you can see idea downloading jar packages from the Nexus private repository:

Go to the Nexus warehouse to view the contents of the warehouse, as shown below:

2. Configure the private warehouse address in the POM.xml file (project valid)

In pom.xml, the repository tag is used to configure the Remote repository for the Maven project, as shown in the following example:

    <repositories>
        <repository>
            <! SQL > select * from server where id = 0;
            <id>my-maven</id>
            <! -- Warehouse description -->
            <name>Custom private warehouse</name>
            <! -- Warehouse address -->
            <url>http://localhost:8081/repository/my-group/</url>
            <! Can I download the releases version from this repository? Default is true.
            <releases>
                <enabled>true</enabled>
            </releases>
            <! Snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots snapshots
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
Copy the code

It is recommended to configure the private repository address in settings.xml so that all projects can use that address.

3. Publish the local JAR package to the Nexus repository

View the custom snapshot repository. Currently, there are no related JAR package resources.

Add the following configuration to the pom.xml file:

    <distributionManagement>
        <repository>
            <! SQL > select * from server where id = 0;
            <id>my-maven</id>
            <! -- Warehouse description -->
            <name>Customize the release repository</name>
            <! -- Warehouse address -->
            <url>http://localhost:8081/repository/my-release/</url>
        </repository>
        <snapshotRepository>
            <! SQL > select * from server where id = 0;
            <id>my-maven</id>
            <! -- Warehouse description -->
            <name>Custom snapshot repository</name>
            <! -- Warehouse address -->
            <url>http://localhost:8081/repository/my-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
Copy the code

Run the following command to publish the project to the Nexus repository:

mvn clean deploy
Copy the code

After a successful build, you can view the following contents of the Nexus repository:

One thing worth noting here is how to publish jar packages to the Release repository.


1.0.0-SNAPSHOT
When MVN Clean deploy is executed again, the JAR package is published to the release repository.

You can also upload jar packages to a private repository directly from the Nexus console: