1. Why build Maven private server
First, let’s talk about maven private server. Maven private server is a special remote repository. Usually built in a local area network, used to proxy all external remote warehouses, and can accept internal project upload and download.
So what are the benefits of using Maven private server? The first step is to centrally manage Maven dependencies for an entire project or for multiple projects. Secondly, there are many projects that cannot be directly connected to the Internet, such as The central repository of Maven or ali Cloud agent repository. It is a good choice to build private server on the Intranet. In addition, there are many benefits to build private servers. For example, reduce the network broadband traffic of the external network, reduce the load of the central warehouse or ali cloud agent warehouse and so on.
But that’s all on the Internet. As for why I chose to build a private server. There are two reasons. First of all, due to various historical reasons, there are several JAR packages that are not available in the central warehouse and Ali Cloud warehouse in a project I am in charge of. These JAR packages may be subsystems that have been developed and referenced in my current project. Therefore, when I build local projects or help others build environments, I need to send these packages to each other hand and then import them manually.
Another reason is that WHEN I was building Jenkins for the project integration, I found an uncomfortable spot. For those of you who know Jenkins, the basic workflow of automated build deployment is to pull the code from the specified Git address and package it on the specified server. Because of the nature of my project, the Git repository doesn’t have these packages, just the location information in POM.xml. So during the project packaging process, those particular packages could not be downloaded through the remote repository, so the packaging failed, and the entire build process failed.
So building maven private server became a necessary step for me.
2. Start
2.1 Download and Decompress
I’m using Nexus to build maven server on top of CentOS7. To download and install the Nexus, visit the Nexus website.
Fill in the relevant information:
Upload the downloaded package to the server directory you want to specify, and unzip:
Two directories are generated, nexus-3.37.3-02(nexus service directory) and Sonatype -work(private library directory).
2.2 Checking and Modifying configurations
CD nexus - 3.37.3-02 / etc cat nexus - default. The propertiesCopy the code
Check and configure the configuration file according to your needs. The default startup port on the Nexus is 8081. Check whether 8081 of each server is open.
2.3 Starting the Service
CD nexus - 3.37.3-02 / bin /. / nexus startCopy the code
After successful startup, it can be accessed at http://ip:8081/ :
For your first login, you can view admin.password in this directory, which contains the password. The user name is admin.
2.4 Create proxy warehouse on private server to point to Aliyun warehouse
Then add the newly created Aliyun-proxy to the group in the maven-pulic repository. Because maven-public is a group type, all repositories added to this group are serviced externally.
3. Configure the private server in the project
Configure the relevant configuration information in our project and then use our private server. Here I choose to do the configuration in the project’s POM.xml.
<profile>
<id>uat</id>
<properties>
<build.env>uat</build.env>
<warName>ROOT</warName>
</properties>
<! -- Introduce private server -- download dependencies -->
<repositories>
<repository>
<id>maven-nexus</id>
<name>maven-public</name>
<url>Private servers IP http:// : 8081 / repository/maven - public /</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<! -- Configure private server download plugin -->
<pluginRepositories>
<pluginRepository>
<id>maven-nexus</id>
<name>maven-public</name>
<url>Private servers IP http:// : 8081 / repository/maven - public /</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<! -- Configure private server -- publish dependencies -->
<distributionManagement>
<repository>
<id>releases</id>
<name>maven-releases</name>
<url>Private servers IP http:// : 8081 / repository/maven - releases /</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>maven-snapshots</name>
<url>Private servers IP http:// : 8081 / repository/maven - snapshots</url>
</snapshotRepository>
</distributionManagement>
</profile>
Copy the code
One thing to note here is that if you need to package your project and upload it to a private server, you need to set your account password. Add configuration to settings.xml:
<server>
<id>releases</id>
<username>admin</username>
<password>Your changed password</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>Your changed password</password>
</server>
Copy the code
Select Deploy in IDEA to package and upload the project:
Note:
(Figure from Resources)
4. Type of private server warehouse
(Figure from Resources)
5. Loading sequence of warehouse in private server
This is the loading order, which can be manually adjusted.
If you want to know more about the loading order of Maven’s various repositories, you can refer to this post I wrote earlier:Maven repository load order
6. Reference materials
1. Maven private server tutorial with Nexus (attached: Configuration and use of private server tutorial) 2