Establishment of Maven private server nexus

Time:2020-1-16

Establishment of Maven private server nexus

The rationality of the existence of private service

The dependencies in Maven are downloaded from the server warehouse. There are only two types of Maven warehouses:

  • 1) Local warehouse
  • 2) There are three kinds of remote warehouse: central warehouse, private server and other public warehouse.

Maven users directly connect to the remote warehouse to download components, which is not recommended by Maven (especially for a development team),Maven’s best practice is to use Maven private server to build project deployment and management of the entire team
Private server is a special remote warehouse. It is a warehouse service set up in LAN. Private server acts as a remote warehouse of Wan for Maven users in LAN.When Maven needs to download a component, it requests from the private server. If the component does not exist on the private server, it downloads it from an external remote warehouse, caches it on the private server, and then provides services for Maven’s download request.

Build Maven private server using nexus, nexus is a powerful Maven warehouse manager, which greatly simplifies the maintenance of its own internal warehouse and access to external warehouse. With nexus, you can have complete control over every artifact that you access and deploy in the warehouse you maintain in just one place. Nexus is a “out of the box” system that does not need a database. It uses the file system plus Lucene to organize data. Nexus uses extjs to develop the interface, restlet to provide complete rest APIs, and m2eclipse to integrate with eclipse. Nexus supports WebDAV and LDAP security authentication.

Build your nexus

Having said the benefits of private service, can’t you wait to start building your Maven private service? Then we will start to build our private service together. First, go to nexus’s website http://www.sonatype.org/nexus…, find the package you need, and download (Demo installation on CentOS):

Establishment of Maven private server nexus

If you want to use some historical version of the package, https://help.sonatype.com/rep…, find it by yourself.
First download the corresponding package to the server:

MKDIR tools - create a new tools directory
CD tools enter the Tools Directory
WGet http://download.sonatype.com/nexus/3/nexus-3.14.0-04-unix.tar.gz ා download the corresponding installation package
Tar zxvf nexus-3.14.0-04-unix.tar.gz
mv nexus-3.14.0-04/ /usr/local/nexus
cd /usr/local/nexus/bin

To install the Java running environment:

yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel

Configure private servers

Modify nexus.rc so that root can start nexus. Under / usr / local / nexus / bin /

VIM nexus.rc, delete the comment before run as user and add root: run as user = root

Then press ESC key, input: WQ enter. Then start nexus

 ./nexus run &

The following appears, indicating successful startup

Establishment of Maven private server nexus

You can access it through http: / / localhost: 8081.

Establishment of Maven private server nexus

Manual index synchronization (optional)

First: go to Maven central warehouse to download indexer-cli-5.1.1.jar decompression tool

Next download: Nexus Maven repository index.properties and nexus Maven repository index.gz

Third, put the three files downloaded above into the same path, and decompress them with the following command:

java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d indexer

Finally, copy the index

Nexus3. X copy to / sonatype work / nexus3 / blobs / default, 3. X

The use of Web

First access the corresponding address, and then enter the defaultUser name admin, password admin123

Establishment of Maven private server nexus

Click browse on the left to see the types of various repositories. What are the differences between these types

  • Group: This is a concept of warehouse aggregation. Users can access the configured

All warehouse resources, access order depends on the configuration order 3. X default releases, snapshots, central, configurable on the web page
Click on the web interface

  • Hosted: private warehouse, specially used to store jar files generated by ourselves
  • Third party: third party jar not published to the public network (3. X removed)
  • Snapshots: snapshot warehouse of the local project
  • Releases: official release of local project
  • Proxy: jar published on the public network for example: Spring
  • Central: central warehouse
  • Apache snapshots: Apache private snapshot repository (3. X removed)

Enter the settings page

Establishment of Maven private server nexus

Do the following:

Establishment of Maven private server nexus

Configure setting.xml of Maven (local global configuration)

Configure the private server configuration in the setting.xml file of Maven. After configuration in this way, all POM files of Maven projects that use the configuration locally do not need to configure the private server download related configuration (in the following, 192.179.101.1:8081 needs to be replaced by your own)

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>
    
    <mirrors>
        
        <mirror>
            <id>nexus-releases</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.101.1:8081/content/groups/public/</url>
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>
        <mirror>
            <id>nexus-snapshots</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.101.1:8081/content/repositories/snapshots/</url> 
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>

    </mirrors>

    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>                            
                <repository>
                    <id>nexus-releases</id>
                    <url>http://192.168.101.1:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus-snapshots</id>
                    <url>http://192.168.101.1:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-releases</id>
                    <url>http://192.168.101.1:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>nexus-snapshots</id>
                <url>http://192.168.101.1:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>                
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
        <!--<activeProfile>dev</activeProfile>-->
    </activeProfiles>

</settings>

Shortcut: docker deploy nexus

Docker is really a good thing, fast and convenient. Using docker to deploy nexus is a matter of minutes. The specific commands are as follows:

docker pull sonatype/nexus3
docker run -d -p 8081:8081 --name nexus sonatype/nexus3

After startup, the location http: / / localhost: 8081 can enter the web page. Other operations and configurations are consistent with the above content, so this part is not described here.
Focus on me, focus on testing

Recommended Today

Laravel queue technique: fail, retry or delay

The article was forwarded from the professional laravel developer community. Original link: https://learnku.com/laravel/t When you create a queue job, listener, or subscriber to push to the queue, you may begin to think that once dispatched, it’s up to you, the queue worker, to decide what to do with your logic. Um… It’s not about youCan […]