Maven镜像加速
# 推荐使用 Maven 3.8.4
🔧 原因:在大数据项目中,Maven 3.9 以上版本可能会出现一些编译问题,尤其是在处理复杂依赖时。为了确保编译过程的稳定性,建议使用 Maven 3.8.4 版本。
# 🛠️ 一、Maven 设置 Nexus 私服方案
# 1.1 项目级别配置 (Project-Level)
在项目的 pom.xml
文件中,配置 Nexus 私服并添加用户名和密码的相关配置。
# pom.xml 完整配置:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-project</artifactId>
<version>1.0.0</version>
<!-- 配置私服仓库 -->
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://your-nexus-server/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<!-- 发布到私服 -->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<url>http://your-nexus-server/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://your-nexus-server/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
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
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
🔑 说明:
repositories
定义从私服仓库下载依赖。distributionManagement
用于发布构件到私服仓库。
# 用户名和密码配置:
为了保证私服的安全性,用户名和密码不直接写在 pom.xml
中。你可以通过全局的 settings.xml
文件来配置认证信息,避免泄露凭证。
# 1.2 全局配置 (Global-Level)
通过 ~/.m2/settings.xml
来配置用户名和密码,适用于所有 Maven 项目。
# settings.xml 配置:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<!-- 配置 Nexus 私服为中央仓库的镜像 -->
<mirror>
<id>nexus-mirror</id>
<mirrorOf>central</mirrorOf>
<url>http://your-nexus-server/repository/maven-public/</url>
</mirror>
</mirrors>
<servers>
<!-- 配置私服的认证信息 -->
<server>
<id>nexus-releases</id>
<username>your-username</username>
<password>your-password</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>your-username</username>
<password>your-password</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://your-nexus-server/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<!-- 激活 Nexus 配置 -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
🔐 说明:
servers
标签中包含了用户名 (your-username
) 和密码 (your-password
) 的配置。- 这样就不会在
pom.xml
中暴露敏感信息,保障了安全性。
# 1.3 选择建议:
- 项目级别:在
pom.xml
中配置私服仓库和发布仓库,而认证信息通过全局settings.xml
配置。 - 全局级别:通过
settings.xml
为所有项目配置认证信息,避免在pom.xml
中泄露敏感信息。
建议将用户名和密码信息安全地存放在 ~/.m2/settings.xml
中,而不是在 pom.xml
中硬编码敏感信息。
本人更倾向于全局设置:
我这里做了统一的汇聚,关联所有的下载镜像:
# 📦 二、在 Bigtop 项目中编译案例—Zookeeper
# 2.1 编译日志
# zookeeper 基于 gradle 打 rpm 的编译
gradle \
zookeeper-rpm \
-PparentDir=/usr/bigtop \
-Dbuildwithdeps=true \
-PpkgSuffix \
-d
1
2
3
4
5
6
7
2
3
4
5
6
7
Downloaded from nexus: http://172.20.0.2:8081/repository/maven-public/org/codehaus/jackson/jackson-core-asl/1.1.1/jackson-core-asl-1.1.1.jar (104 kB at 43 kB/s)
Downloaded from nexus: http://172.20.0.2:8081/repository/maven-public/com/sun/jersey/jersey-client/1.1.5.1/jersey-client-1.1.5.1.jar (90 kB at 37 kB/s)
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ zookeeper-contrib-rest ---
[INFO]
...
1
2
3
4
5
6
2
3
4
5
6
# 2.2 使用 ambari-env 一键解决环境准备问题
项目地址: ambari-env: Ambari+Bigtop 一站式编译和部署解决方案 (gitee.com) (opens new window)