Maven Repository
验证:未记录
- 适用版本
- 未记录
- 验证范围
- 尚未登记验证记录。
本文缩写(英文全称与中文含义)
| 缩写 |
英文全称/名称 |
中文含义 |
| CA |
Certificate Authority |
证书颁发机构 |
| CI |
Continuous Integration |
持续集成 |
| TLS |
Transport Layer Security |
传输层安全协议 |
| URL |
Uniform Resource Locator |
统一资源定位符,通常指访问地址 |
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>
settings.xml 的 server ID 必须匹配目标 repository / distributionManagement ID;名称不匹配时,有凭据文件也无法正确认证。
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