1. Basic introduction
1, if there is no build private server will have any problems?
- If there is no private servers, we need all the necessary components are by the Maven central repository or third-party Maven download to a local warehouse, and all the people in a team are repeated from Maven warehouse download component no doubt increased the load and wasted network bandwidth, if speed is slow, can also affect the project’s progress.
- In addition, in many cases project development takes place on the Intranet, and there may be no connection between Maven’s central repository and a third-party Maven repository.
- If the public components we developed need to be provided to other projects, we also need to build private servers.
2, the advantages of building private servers
The concept of Maven private server is to set up a Maven repository server locally and maintain the local repository while proxying the remote repository. When we need to download some artifact, if the local repository doesn’t have it, go to the private server to download it, and if the private repository doesn’t have it, go to the central repository to download it. Doing so has the following advantages:
- Reduce network bandwidth traffic
- Speeding up Maven builds
- Deploying third-party Artifacts
- Improve stability and control
- Reduce load in the central warehouse
3. Introduction to Nexus
Nexus is a dedicated Maven repository management software, which not only can build Maven server, but also has the following advantages that make it the most popular Maven repository manager:
- Provides a powerful warehouse management function, component search function
- It is reST-based and the friendly UI is a REST client for Ext.js
- It takes up less memory
- Based on a simple file system rather than a database
Second, Nexus service installation
Use the Docker image for installation
(1) Run the following command to download the Nexus3 image:
docker pull sonatype/nexus3 |
---|
(2) Then run the following command to create the host mount directory:
mkdir - the vp/usr/local/docker/nexus - data |
---|
(3) Finally, run the following command to run Nexus3 container:
1 | docker run -d --name nexus3 -p 8081:8081 -v /usr/local/nexus-data:/var/nexus-data sonatype/nexus3 |
---|
(4) Also do not forget to run the following command to open port 9081:
1 | firewall-cmd --permanent --add-port=9081/tcp |
---|
2 | firewall-cmd --reload |
---|
Configuration of Nexus service
(1) After the Nexus service is started, we use the browser to access http://IP(VM server IP):9081/, click the login button in the upper right corner:
(2) for the first time login prompt password stored in the/usr/local/sonatype – work/nexus3 / admin password file, we view the content of the file on the server, and then as a password:
(3) After login, we will set a new password:
(4) The following interface is displayed after login:
(1) Default warehouse description
- Maven-central: Maven central library, drawn by default from repo1.maven.org/maven2/…
- Maven-releases: Private library release JAR, set the Deployment policy to Allow Redeploy for the first installation
- Maven-snapshots: snapshots of private libraries (debug versions) JAR
- Maven-public: repository group, which combines the above three repositories to provide external services. Maven-public is used in local Maven basic configuration settings. XML or project pem.xml
(2) Warehouse Type Description:
- Group: this is a concept of warehouse aggregation. The user’s warehouse address selects the address of the group to access the warehouse configured in the group for the convenience of the developer. Maven-public is a Group repository with multiple internal access orders depending on the configuration order. By default, it Releases Releases, Snapshots, and Central, which you can set yourself.
- Hosted: Private repository, a release repository for internal projects, dedicated to storing our own generated JAR files
- Snapshots: Stores snapshots of local projects
- Releases: The official release of a local project
- Proxy: indicates the proxy type. It searches for the data warehouse from the Remote central warehouse (click the Remote Storage property value under the Configuration TAB of the corresponding warehouse, that is, the path of the Remote warehouse to be proxy), for example, the Aliyun Maven warehouse can be configured
- It’s a central warehouse
Iv. Configure aliyun public warehouse
The default lookup mode for Maven-group on Nexus is Maven-releases –> Maven-snapshots –> Maven-Central. We added an Alibaba cloud repository in the middle to speed up access.
Select proxy Type
Fill in the following information
Warehouse name: maven - aliyun ali cloud remote maven warehouse address: http://maven.aliyun.com/nexus/content/groups/public/ the other options: by defaultCopy the code
Modify maven-public repository references and order:
At this point, configuration complete! When using maven’s Maven-public repository address, we access it in the following order: local repository > Private Releases Maven-snapshots > Remote Aricloud Maven repository > Remote Central repository.