Linux 系统搭建 Maven 环境
直接官网下载 Maven 然后解压安装,离线安装的话请先下载好上传到服务器1
wget https://dlcdn.apache.org/maven/maven-3/3.8.7/binaries/apache-maven-3.8.7-bin.tar.gz
解压安装
1 | tar -zxvf apache-maven-3.8.7-bin.tar.gz -C /app/service |
顺便创建本地仓库文件夹1
mkdir -pv /app/data/maven/repo
环境变量
设置当前用户环境变量:~/.bashrc,继承 /etc/profile 中的变量1
2echo "export MAVEN_HOME=/app/service/maven" >> ~/.bashrc
echo "export PATH=\$PATH:\$MAVEN_HOME/bin" >> ~/.bashrc
环境验证
1 | source ~/.bashrc |
修改设置
修改 maven 目录下的 settings.xml
文件1
2mv /app/service/maven/conf/settings.xml /app/service/maven/conf/settings.xml.bak
vi /app/service/maven/conf/settings.xml1
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127<settings>
<!--设置本地仓库位置-->
<localRepository>/app/data/maven/repo</localRepository>
<servers>
<!--设置私库认证信息(访问)-->
<server>
<id>nexus</id>
<username></username>
<password></password>
</server>
<!--设置私库认证信息(发布)-->
<server>
<id>nexus-releases</id>
<username></username>
<password></password>
</server>
<server>
<id>nexus-snapshots</id>
<username></username>
<password></password>
</server>
</servers>
<mirrors>
<!--设置私有仓库,Maven 所有的请求都由私库处理-->
<mirror>
<id>nexus</id>
<name>Nexus Releases Repository</name>
<mirrorOf>*</mirrorOf>
<url>http://192.168.254.100:8081/repository/public/</url>
</mirror>
<!--设置阿里云公共仓库-->
<mirror>
<id>aliyun</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public/</url>
</mirror>
</mirrors>
<profiles>
<!--设置 JDK 版本-->
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<!--设置私库信息-->
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>Nexus Releases Repository</name>
<url>http://192.168.254.100:8081/repository/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Nexus Releases Repository</name>
<url>http://192.168.254.100:8081/repository/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
<!--覆盖中央仓库设置,开启 releases 和 snapshots 版本的下载-->
<profile>
<id>central</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!--激活私库信息-->
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>central</activeProfile>
</activeProfiles>
</settings>