Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

As a beginner configure Maven general online search. Then you see the various configuration file fragments, first configuring the mirror, then configuring the repository. After this, configure the maven path and configuration file path in IDEA.

One important configuration that these articles completely fail to cover is activeProfiles.

When I configured a variety of, messing around for a long time, idea could not be loaded into the warehouse information I configured.

At the end of the day, you just need to configure activeProfiles. Basically 99% of the articles don’t do this, and you’ll fall into a trap if you don’t read the documentation carefully.

Under activeProfiles is configured the profile to be activated.

<activeProfiles>  
  <activeProfile>profileid</activeProfile>  
</activeProfiles> 
Copy the code

# Maven settings. XML configures the configured profile

<profile>
    <id>profileid</id>
    <repositories>
		<repository>
			<id>snapshots</id>
			<name>snapshots</name>
			<url>http://xxx.xxx.xx.xx:8081/nexus/content/repositories/snapshots/</url>
		</repository>
    </repositories>
</profile>
Copy the code

We use a private warehouse built in-house.

The relationship between mirror and warehouse

<mirror>
	<id>aliyunmaven</id>
	<mirrorOf>central</mirrorOf>
	<name>aliyun maven</name>
	<url>https://maven.aliyun.com/repository/public</url>
</mirror>
Copy the code

Mirror: Mirror is an interceptor that intercepts Maven requests for remote Repository and redirects the requested remote Repository address to the mirror’s configured address.

Interception rule: Central intercepts requests from the central repository if mirrorOf is specified. The mirrorOf value is the repository ID. We can call it “snapshots” and call it “central”, but we don’t need to call it “snapshots”.

Repository: A repository is a third-party library that a project relies on. The location of this library is called a repository.

So not both the repository and the mirror need to be configured, and many articles don’t realize this. If I only use a private repository built in-house, I don’t need to configure mirrors at all.

The idea of configuration maven

file->settings

After configuration, refresh and reload to download maven dependencies

If it is not good, turn off IDEA and restart it, IDEA will be convulsed