Links#
https://maven.apache.org/settings.html
https://maven.apache.org/guides/mini/guide-deployment-security-settings.html
https://maven.apache.org/guides/mini/guide-mirror-settings.html
https://maven.apache.org/guides/mini/guide-proxies.html
1. Important Points#
local repository:
~/.m2/repository
remote repository:
Maven Central, Nexus, Artifactory, GitHub Packages
settings.xml:
user/CI side configuration for credentials, mirrors, proxies
2. Repository Types#
| Type |
Purpose |
| local |
cache on developer machine or CI runner |
| proxy |
cache Maven Central and third-party repos |
| hosted release |
internal release artifacts |
| hosted snapshot |
internal SNAPSHOT artifacts |
| group |
one URL that aggregates multiple repos |
3. settings.xml#
<settings>
<servers>
<server>
<id>company-releases</id>
<username>${env.MAVEN_REPO_USER}</username>
<password>${env.MAVEN_REPO_PASSWORD}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>company-maven</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus.example.com/repository/maven-public/</url>
</mirror>
</mirrors>
</settings>
server id:
must match repository id in distributionManagement or repository config
4. distributionManagement#
<distributionManagement>
<repository>
<id>company-releases</id>
<url>https://nexus.example.com/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>company-snapshots</id>
<url>https://nexus.example.com/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
5. Private Dependency Repository#
<repositories>
<repository>
<id>company-public</id>
<url>https://nexus.example.com/repository/maven-public/</url>
</repository>
</repositories>
enterprise rule:
prefer mirror in settings.xml
avoid scattering repository URLs across many POMs
6. Proxy#
<proxies>
<proxy>
<id>corp-proxy</id>
<active>true</active>
<protocol>https</protocol>
<host>proxy.example.com</host>
<port>8080</port>
</proxy>
</proxies>
7. TLS / Custom CA#
keytool -importcert \
-alias company-ca \
-file company-ca.pem \
-keystore truststore.jks \
-storepass changeit
export MAVEN_OPTS="-Djavax.net.ssl.trustStore=$PWD/truststore.jks -Djavax.net.ssl.trustStorePassword=changeit"
do not:
disable TLS verification
put truststore password in repository
8. Verify#
./mvnw help:effective-settings
./mvnw dependency:get -Dartifact=org.junit.jupiter:junit-jupiter:5.10.2