Maven 多仓库配置 - 使用 activeProfiles 使阿里云和 Apache 仓库同时生效
要配置 Apache Maven 仓库使用多个仓库,可以在 Maven 的 settings.xml 文件中添加多个仓库配置。以下是一个示例:
<settings>
...
<profiles>
<profile>
<id>aliyun</id>
<repositories>
<repository>
<id>aliyun</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>apache</id>
<repositories>
<repository>
<id>apache</id>
<url>https://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>aliyun</activeProfile>
<activeProfile>apache</activeProfile>
</activeProfiles>
...
</settings>
上面的配置文件中定义了两个 profile,分别是 'aliyun' 和 'apache',每个 profile 中都配置了一个仓库。然后在 'activeProfiles' 中设置了同时生效的两个 profile。
这样配置后,当使用 Maven 构建项目时,同时会从两个仓库中下载依赖。
原文地址: https://www.cveoy.top/t/topic/peRo 著作权归作者所有。请勿转载和采集!