-
打开 Maven 的
settings.xml
文件,该文件通常位于 Maven 的安装目录下的conf
文件夹中。如果没有该文件,您可以根据 Maven 提供的模板创建一个新的settings.xml
文件。 -
在
settings.xml
文件中添加<profiles>
部分,然后在<profiles>
下添加多个不同的<profile>
,每个<profile>
配置一个仓库地址。示例配置如下:<profiles> <profile> <id>repo1</id> <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </profile> <profile> <id>repo2</id> <repositories> <repository> <id>my-repo</id> <url>http://mycompany.com/repo</url> </repository> </repositories> </profile> </profiles>
-
确保每个
<profile>
都有一个唯一的<id>
,并且在每个<profile>
下面可以配置多个仓库地址。 -
接下来,在
<activeProfiles>
部分,指定需要激活的仓库配置。您可以选择将所有的<profile>
都激活,或者只激活特定的<profile>
。示例配置如下:<activeProfiles> <activeProfile>repo1</activeProfile> <activeProfile>repo2</activeProfile> </activeProfiles>
-
保存
settings.xml
文件,并确保在执行 Maven 构建时正确引用该文件。 -
通过以上步骤,您就可以在 Maven 中配置多个仓库地址了。当执行 Maven 构建时,Maven 将会从这些配置的仓库地址中查找依赖。
maven进阶--配置多仓库地址
最新推荐文章于 2025-04-16 14:55:12 发布