Maven Ali Cloud Repository uses a few tricks
Introduction to the
In daily work or study, I often need to look at other people’s project example code, but maven’s dependency import often has some problems. Maven mirror is used abroad by default, which is known to be ridiculously slow. Sometimes when I go out for a walk, the import has not been completed, resulting in too much fishing time.
The use of domestic mirror that will be very very fast, fast two or three minutes, slow more than ten minutes, acceptable. But in the process of use will also encounter many problems, such as setting and dependency can not find the problem, the following introduces their use of Ali Cloud some skills, I hope to inspire you
Ali Cloud warehouse configuration
The first step is to configure the mirror warehouse as Ali Cloud, there are two configuration methods, one is global configuration, the other is a single project configuration
It is recommended to use global configuration. Create two global configuration files for switching with IDEA
Global configuration
XML file and name it setting.aliyun. XML. Open the file and add the mirror child node to the tag.
<mirrors>
<! -- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> -->
<mirror>
<id>aliyunmaven-pulic</id>
<mirrorOf>*</mirrorOf>
<name>aliyun-public</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
Copy the code
Single POM.xml configuration
This scope is relatively small, on a single pom. The XML configuration, use rise also calculate can, but not the individual feels that all the above, there are times when you need to use multiple agent warehouse, configuration up a little trouble, in the back of the official ali cloud configuration instructions are included in the reference links, you can also explore your own, This is one of the few studies
<repository>
<id>spring</id>
<url>https://maven.aliyun.com/repository/spring</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
Copy the code
IDEA switching is used together
After the configuration is complete, configure in IDEA to switch between the domestic source and the foreign source. The configuration is as follows:
Enter the Maven configuration page of IDEA as shown in the preceding figure. 1 in the figure configurs the Maven root path. 2 is the configuration file configuration. You can switch between different configuration files at will. 3 is dependent on the download path
After the completion of the configuration can be used, the use of Ali cloud dependency soon completed
Rely on missing tips
In the dependency import, often encounter XXXX: XXXX: POM can not be found, can not download the situation, and some cases switch to foreign sources can normally download, but it is very slow, it is very annoying, after exploration, most of the dependency can not download the problem can be solved by directly specifying a specific version. Here is an example:
The dependency version cannot be found. The solution to this problem is to specify a specific dependency version. Details will be found later
Could not find artifact org.codehaus.mojo:flatten-maven-plugin:pom: in aliyunmaven-pulic (https://maven.aliyun.com/repository/public)
Copy the code
To solve this problem, we can find the dependent version in ali Cloud warehouse, and then specify or modify the dependent version in the configuration file
First open the ali cloud warehouse search address: maven.aliyun.com/mvn/search, the diagram below:
In the search above, you can fill in the artifact with faulty dependent groups and artifacts on the right, then search and see the many versions below, just select the one that looks good (most of the versions are the same). You can also switch the search mode on the left side. You can directly enter some keywords, such as latten-Maven-plugin. If the recognition is high, you can use keywords to search. If not, a more complete search method, GAV, can be used
So that pretty much solves most of the problems, and hopefully it’s helpful