Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Maven warehouse

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to configure the Maven warehouse, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to configure the Maven warehouse. Let's take a look.

When Maven is used to manage jar package dependencies in a project, the following situations often occur:

1. Domestic access to maven default remote central mirror is very slow.

2. Replace the remote central mirror with Ali's mirror.

3. Some jar packages are missing in Ali Cloud image.

4. Use both private and public warehouses

In view of the above, we need to make Maven support multi-warehouse configuration.

Separate warehouse configuration

When only one repository is configured, it is relatively simple to configure globally in the settings.xml file of Maven. Take the image of Aliyun as an example:

Alimaven aliyun maven http://maven.aliyun.com/nexus/content/groups/public/ central

Just add a new mirror configuration. To achieve a single warehouse, set mirrorOf to *.

The asterisk configured in mirrorOf indicates that it matches all artifacts, that is, everything uses the proxy address here. The mirrorOf above is configured with a specific name, which refers to the name of repository.

Image configuration description:

1. Id: the unique ID of the image

2. Name: name description

3. Url: address

4. MirrorOf: specify the image rules and when to pull from the image repository. Among them

*: match all, and all the contents are pulled from the image

External:*: pulls from the image repository except for the local cache

Repo,repo1: repo or repo1, where repo refers to warehouse ID

*,! repo1: all warehouses except repo1

Multi-warehouse configuration

So is it possible to configure a few more mirror for multi-warehouse configuration? This configuration will not take effect.

The correct thing to do is to configure multiple profile under the profiles node, and activate it after configuration.

Boundlessgeo boundlessgeo https://repo.boundlessgeo.com/main/ true true always aliyun aliyun http://maven.aliyun.com/nexus/content/groups/ Public/ true true always maven-central maven-central http://central.maven.org/maven2/ true true always

Activate by configuring the activeProfiles child node:

Boundlessgeo aliyun maven-central

At this point, if the local Maven configuration is used in Idea, you will see the profile option similar to the one in the following figure in the Maven management of the project.

When packing, check the profile you are using. If you use the Maven command to package and execute the command, the format is as follows:

Mvn-Paliyun...

1. If the id of the aliyun warehouse is set to central, the default remote warehouse in maven will be overwritten.

The 2.aliyun repository can also be configured directly in the mirrors tag without configuration. If the mirrorOf of the mirrors image repository is set to central, the default repository can also be overridden.

Configure the image in the project

Adding multiple repositories to the project is achieved by modifying the pom file in the project.

Idea: add multiple repository nodes under the repositories node of the pom file in the project (if you don't add it manually), each repository node is a repository.

The configuration effect is as follows:

Central-repo1 Maven Repository Switchboard http://repo1.maven.org/maven2/ default true

The id here is the ID that mirrorOf will use.

In the course of practice, it is found that configuring the warehouse configuration alone will not take effect, and you need to define a warehouse configuration with mirrorOf as central-repo1 in setting.xml, which is compared with the id of this configuration.

The comparison configuration in setting.xml is as follows:

Central Maven Repository Switchboard https://repo1.maven.org/maven2/ central-repo1

Domestic images worthy of collection

Alimaven aliyun maven http://maven.aliyun.com/mvn/view central jboss-public-repository-group central JBoss Public Repository Group http://repository.jboss.org/nexus/content/groups/public ibiblio central Human Readable Name for this Mirror. Https://maven.aliyun.com/mvn/view central Maven Repository Switchboard http://repo1.maven.org/maven2/ central repo2 central Human Readable Name for this Mirror. This is the end of http://repo2.maven.org/maven2/ 's article on "how to configure Maven Warehouse". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to configure Maven warehouse". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 215

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report