Maven private server problem summary

Recently, I am working on migrating my company's internal projects to the maven platform. Need to build a maven private server, choose Nexus (don't confuse it with Google's Nexus phone). As for why you should build your own maven private server, there are three reasons:

  1. The access speed of maven's own central library is relatively slow, and the great wall will be noisy again and again, and it will be intermittent.
  2. Some jar packages are not available in the maven central repository due to copyright reasons, such as the oracle JDBC driver. In addition, there will also be older open source jar packages used in some projects, and the central repository is useless. In this case, we need to manually upload the jar package to the private server.
  3. The jar package developed by the company itself is not open source and cannot be uploaded to the maven central warehouse, but can only be deployed to the private server.

As for how to install the Nexus Maven private server, there are many tutorials on the Internet, and they are very simple, so I will not make repeated wheels. The following is a summary of the problems encountered by myself, in order to help latecomers avoid detours.

Private server data source

Most of the jar packages in the private server come from another private server or a central warehouse. So the first thing is to specify the data source of the private server. Nexus is set to Maven Central by default, but Maven Central is too slow to be considered. I know of two stable maven mirrors in China, http://maven.oschina.net/content/groups/public/ and http://mirrors.ibiblio.org/maven2/ . The two and maven central warehouses cannot be exactly the same, at least there is a time delay, and the latest version of jar packages in some maven central warehouses may take a certain period of time to have them. After observing it, the update frequency of oschina is faster, so I chose oschina. Generally, you don't need to worry too much about the delay, and the two mirrors can meet the requirements in most cases.

The setting steps are, first log in, Repositories=>Central=>Configuration=>Remote Storage Location. Please select Download Remote Indexes as True (default is False), and finally remember to click the Save button.

The screenshot is as follows:

How to handle download failures

pom.xml often reports that the jar package cannot be found, which is very annoying and headache. In a word, this is a network problem and the download failed. Under normal circumstances, jar packages exist in three places, Local warehouse, Nexus private server warehouse, mirror or maven central warehouse. Subject to the listed order, the search process is from front to back, and the download process is from back to front. The download process is divided into two parts, mirror or maven central warehouse => Nexus private server warehouse, Nexus private server warehouse => Local warehouse, both of which may have problems. It's okay if there is a problem, just try again, but maven will generate a broken file ending with lastUpdated in the Local repository, a wrong cache (cache). To be able to retry correctly, the only way to do this is to manually delete the cache.

First determine which section is wrong, select Repositories=>Central=>Brower Storage, and see if the corresponding jar package is available on the Nexus private server. If not, it means that the mirror or maven central warehouse => Nexus private server warehouse download failed, otherwise the Nexus private server warehouse => Local repository download failed.

Mirror or maven central repository => Nexus private server repository download failure handling method

Delete the cache of the Local repository. Open the ~/.m2/repository folder and delete the folder where the error jar package is located (you can also delete only specific sub-files to improve efficiency). Delete the cache of the Nexus private server repository. Repositories=>Central=>Brower Storage, select the corresponding directory tree, right-click first Expire Cache, then Delete.

The screenshot is as follows:

Nexus private server warehouse => Local warehouse download failure processing method

This situation is much simpler, just delete the cache of the Local warehouse. The steps are as above.

Epilogue

Everything has advantages and disadvantages, and maven is the same. Personally, I feel that maven is a bit too complicated, it is difficult to get started, and it is not robust enough. It often takes a lot of time to fight errors and warnings, which is tiring.

 

 

 

 

--------------------

 

There is another question: why can't the plugin always be downloaded from the central repository? ? ? (when mvn clean install), other JARs can

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326942579&siteId=291194637