Maven 多仓库配置:使用 activeProfiles 切换阿里云和 Apache 仓库
要配置 Apache Maven 仓库中的多个仓库(例如阿里云和 Apache 仓库),可以使用 Maven 的 'settings.xml' 文件来完成。在 'settings.xml' 文件中,可以配置多个仓库,并使用 'activeProfiles' 来指定要使用的仓库。
以下是一个示例的 'settings.xml' 文件配置:
<settings>
<activeProfiles>
<activeProfile>aliyun</activeProfile>
</activeProfiles>
<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>
</settings>
在上述示例中,我们定义了两个仓库配置:'aliyun' 和 'apache'。'aliyun' 仓库使用了阿里云的 Maven 仓库地址,而 'apache' 仓库使用了 Apache Maven 仓库地址。
要指定要使用的仓库,可以通过在 'activeProfiles' 中指定 'aliyun' 或 'apache' 来选择。例如,上述示例中我们将 'aliyun' 添加到 'activeProfiles' 中,表示要使用阿里云的仓库。
通过使用 'activeProfiles' 和 'profiles',我们可以配置 Maven 使用多个仓库,并根据需要切换使用的仓库。
原文地址: https://www.cveoy.top/t/topic/peRc 著作权归作者所有。请勿转载和采集!