Maven构建过程中仓库识别

Maven 构建过程中自动识别并使用 Fit2Cloud 仓库


方式一:项目级配置(推荐)

作用范围:仅当前项目有效(最常见做法)。

在项目的 pom.xml 中添加以下段落(放在 <project> 内任意位置):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<repositories>
<repository>
<id>fit2cloud-public</id>
<name>Fit2Cloud Public Repository</name>
<url>https://repository.fit2cloud.com/repository/fit2cloud-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>fit2cloud-plugin</id>
<url>https://repository.fit2cloud.com/repository/fit2cloud-public/</url>
</pluginRepository>
</pluginRepositories>

适用场景:

  • 项目有特定依赖(如 io.metersphere)仅存在 Fit2Cloud 仓库;
  • CI/CD(如 Jenkins、GitLab Runner)构建时无需额外修改 settings.xml;
  • 最可控、最通用。

方式二:全局配置(所有项目共享)

作用范围:当前机器上所有 Maven 构建。

编辑或创建:

~/.m2/settings.xml

添加:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<settings>
<profiles>
<profile>
<id>fit2cloud-public</id>
<repositories>
<repository>
<id>fit2cloud-public</id>
<url>https://repository.fit2cloud.com/repository/fit2cloud-public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>fit2cloud-plugin</id>
<url>https://repository.fit2cloud.com/repository/fit2cloud-public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>fit2cloud-public</activeProfile>
</activeProfiles>
</settings>

适用场景:

  • 需要多项目共享同一源;
  • CI 构建节点统一使用;
  • 不想改动项目 pom。

方式三:命令行临时指定(一次性)

如果你只是临时构建,可直接在命令行中指定仓库:

1
2
mvn clean install \
-DaltDeploymentRepository=fit2cloud::default::https://repository.fit2cloud.com/repository/fit2cloud-public/

或者强制刷新并下载依赖:

1
2
mvn -U clean package -DskipTests \
-Dmaven.repo.remote=https://repository.fit2cloud.com/repository/fit2cloud-public/

⚠️ 注意:
-Dmaven.repo.remote 已在部分新版 Maven 弃用,推荐方式仍是 方式一或二


验证

执行:

1
mvn dependency:resolve

若日志中出现:

Downloading from fit2cloud-public: https://repository.fit2cloud.com/repository/fit2cloud-public/...