_Maven, as the current mainstream project management tool, has great performance in dependency management, system building, etc.However, it is a nightmare for users to visit Maven warehouses abroad. Building a private Maven warehouse is one of the effective ways to solve this problem.
Private warehouse principles
- Developers or build systems build systems based on local Maven component libraries;
- The Maven Local Library publishes project self-builds to the Maven Private Library for publishing sharing and versioning, and loads locally required dependencies from the Maven Private Library.
- If the required component does not exist in the Maven private library, scan the configured external central warehouse or mirror for download, then download to the local library, and do not need to download the component from outside again for secondary use.
Private warehouse benefits
- Once and for all: download components to the private warehouse in the internal network environment first, then use them without duplicate downloads abroad or mirror, solve the speed and bandwidth occupancy of the external network, and improve the efficiency of development;
- Self-builder publishing and sharing: Modular project management can be achieved by publishing project components to a private repository.
Build private warehouses
_Nexus is the Maven Warehouse Manager. It also provides powerful warehouse management and component search functions. It is based on REST. The friendly UI is an extjs REST client. It takes up less memory and is based on a simple file system rather than a database.These advantages make it the most popular Maven warehouse manager.
_This section describes how to set up a private Nexus Maven repository on Linux.
Note: Nexus 3. * The current latest version 3.2.1 needs to run in JVM1.8 and later environments. The version of Nexus used in this article is 2.14.3. For more information, see Official Documents.
- Install JDK: [Reload] Install JDK 1.7 on Linux using RPM
- Download Nexus: https://www.sonatype.com/download-oss-sonatype
-
Install Nexus:
_Upload the compressed package to the server and unzip to get two directories:tar -zxvf nexus-2.14.3-02-bundle.tar.gz
- nexus-2.14.3-02 is the home directory of nexus services;
- sonatype-work is a real repository and contains the configuration of nexus, such as timed tasks, user configurations, and so on.
Modify Startup Port
_Nexus default port is 8081, we recommend that you modify it to another port and modify the nexus/conf/nexus.properties configuration file.-
Start Nexus
_Start by executing the following command:/app/nexus/nexus-2.14.3-02/bin/nexus start
_If Root user exceptions occur and solutions are as follows:
_nexus command usage is as follows:
nexus { console | start | stop | restart | status | dump }
-
Logon Console
_The console address is as follows, and the port is identical to the configuration file nexus.properties:http://10.0.79.28:8081/nexus/
The login page is as follows:
Default login/password is admin/admin123 -
Repository
Warehouse Classification:- hosted - a local warehouse, where we usually deploy our own components;
- Releases: Stores the Releases project submitted in Maven
- Snapshots: Store Snapshots items submitted in Maven
- 3rd party: Store third-party jar packages that are not in the Maven Central Warehouse
- Proxy - Proxy warehouses, which are used to proxy remote public warehouses, such as the maven central warehouse;
- Virtual, a virtual warehouse, is a logical view of another warehouse configured in Nexus;
- Group - A warehouse group used to merge multiple hosted/proxy warehouses. Usually we configure maven dependent warehouse groups.
- hosted - a local warehouse, where we usually deploy our own components;
Manage hosted repository
New Agent Warehouse
http://repo1.maven.org/maven2
http://maven.aliyun.com/nexus/content/groups/public/
http://maven.oschina.net/content/groups/public/
http://repository.jboss.com/nexus/content/repositories/root_repository/maven2/
http://maven.springframework.org/releaseDownload Remote Index
Add new agent to warehouse group
Manage warehouse groups
Use private warehouses
-
Use in separate projects
The pom.xml file for the configuration project is as follows:<repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http://localhost:8081/nexus/content/groups/public/</url> </repository> </repositories>
Where the <url>tag is as follows:
-
Local Maven Global Usage
Configure the Maven configuration file settings.xml as follows:<profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus</id> <name>local private nexus</name> <url><Your Nexus IP>/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>nexus</id> <name>local private nexus</name> <url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://<Your Nexus IP>/nexus/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>nexus</id> <name>local private nexus</name> <url>http://<Your Nexus IP>/nexus/content/groups/public-snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> ... <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles>
Remember to select the profile in eclipse
-
Upload Build to Private Warehouse
Configure the Maven configuration file settings.xml as follows:<settings> ... <servers> <server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server> </servers> ... </settings>
The configuration project pom.xml configuration file is as follows:
<project>
...
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://<Your Nexus IP>/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://<Your Nexus IP>/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
...
</project>
The IDS in the two profiles must be id entical, execute the following command:
mvn deploy
Reference resources:
1. Nexus Builds maven Private Warehouse
2. Maven Scattered Notes - Configure Nexus