为jenkins服务器搭建maven环境
1.下载安装包,进入官方网站http://maven.apache.org/download.cgi,准备下载apache-maven-3.5.3-bin.tar.gz
当前页面是最新版本的,如果需要使用历史版本,点击蓝色字体archives,红色箭头所示,即进入下载页面。
我需要下载3.5.3版本的,点击3.5.3,选择二进制还是src源码,
选择下载二进制的tar.gz格式
2.创建文件夹,并解压
$sudo mkdir /usr/local/maven
$sudo tar -zxvf apache-maven-3.5.3-bin.tar.gz -C /usr/local/maven
3.配置maven环境变量
我习惯在/etc/profile.d/目录下配置环境变量,便于管理,而非直接在/etc/profile增加变量内容,做到尽量不改动系统文件。
$ cd /etc/profile.d/
$ sudo vim maven.sh
MAVEN_HOME=/usr/local/maven/apache-maven-3.5.3
PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
#soure /etc/profile #在root用户下执行source,使环境变量生效。
4.验证
$ mvn -v
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: /usr/local/maven/apache-maven-3.5.3
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_141/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.0.0-32-generic", arch: "amd64", family: "unix"
5.创建及修改本地仓库地址
$ sudo mkdir /usr/local/mvn-repository #创建新仓库地址
$sudo vim /usr/local/maven/apache-maven-3.5.3/conf/settings.xml #在setting.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">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>/usr/local/mvn-repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
6.更改镜像下载地址
在/usr/local/maven/apache-maven-3.5.3/conf/settings.xml里增加阿里云下载地址,红色框选内容所示:
结束。