Maven Private/Multiple Repository Setup
If your Java project has a private Maven repository, or you have multiple Maven repositories, you need to additionally set up the repository info, otherwise you won't successfully get the dependencies or plugins, and see the following error message:
Could not find artifact xxxx in central(https://repo.maven.apache.org/maven2).
This essay will show you how to set up maven to connect with private/multiple repositories.
- Add repository info in
pom.xml
, replace repository info with yours
<distributionManagement>
<snapshotRepository>
<id>your-snapshot</id>
<name>Your internal repository</name>
<url>http://xxxxx/url-to-snapshot-repository</url>
</snapshotRepository>
<repository>
<id>your-releases</id>
<name>Your internal repository</name>
<url>http://xxxxx/url-to-releases-repository</url>
</repository>
</distributionManagement>
- Set up
custom-settings.xml
file for Maven settings, replace repository id, url and server account info with yours
<?xml version="1.0" encoding="utf-8" ?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>your-snapshot</id>
<username>admin</username>
<password>admin123456</password>
</server>
<server>
<id>your-releases</id>
<username>admin</username>
<password>123456admin</password>
</server>
</servers>
<mirrors>
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>dummy</mirrorOf>
<url>http://0.0.0.0/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>your-releases</id>
<url>http://xxxxx/url-to-releases-repository</url>
<release>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</release>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>your-snapshot</id>
<url>http://xxxxx/url-to-snapshot-repository</url>
<release>
<enabled>false</enabled>
</release>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>your-releases</id>
<url>http://xxxxx/url-to-snapshot-repository</url>
<release>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</release>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
- Override maven settings in Intellij: preference -> maven -> User settings file, click "override", put the above "custom-settings.xml" under ~/.m2, and put the file path in "User setting file", and "apply".