1、下载安装
这个很简单,只需要下载apache-maven-tar.gz
https://maven.apache.org/download.cgi
然后解压到任何路径,并配置如下环境变量
window==> 在系统变量中配置到bin下即可
Linux==> 在/etc/profile 中配置到bin即可
通过mvn -version检查是否已经配置成功
2、配置settings文件
-
1、配置阿里云仓库
-
2、与sonar集成
alibaba的maven仓库地址:
http://maven.aliyun.com/nexus/content/groups/public/
在maven的conf/settings.xml文件中,配置阿里maven仓库
<?xml version="1.0" encoding="UTF-8"?> <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"> <!-- 本地仓库路径,默认是在-用户工作目录下的.m2文件夹,可修改如下 <localRepository>D:/m2/repo</localRepository> --> <!--代理,不用配置--> <proxies> </proxies> <!--远端仓库的账号和密码,可以不配置,只需要配置下面mirrors即可--> <servers> </servers> <!--只要配置这个就行了远程中央仓库,本地找不到的都会到这里找,一般配置国内比较稳定的阿里巴巴仓库--> <mirrors> <!-- 阿里代理maven中央仓库--> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <!-- 配置远端仓库和sonar,远端仓库可以不配置,因为有mirrors就可以了 --> <profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar</sonar.jdbc.url> <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver> <sonar.jdbc.username>sonar</sonar.jdbc.username> <sonar.jdbc.password>sonar</sonar.jdbc.password> <sonar.host.url>http://localhost:9000</sonar.host.url> </properties> </profile> </profiles> <!--指定profile--> <activeProfiles> <activeProfile>sonar</activeProfile> </activeProfiles> </settings>
3、总结:
-
1、只需要配置mirror就可以了。
因为他是镜像配置,只要本地仓库没有找到,他都会尝试着项maven.repo中央仓库请求,但是如果配置了mirror,那么他就会转向配置的远端镜像仓库,而不是中央仓库,国内用阿里比较稳定
-
2、sonar插件的功能
从sonar服务器下载sonar.jar 包从而拥有代码扫描的能力。同时能够和sonar服务器版本对应上。试想,如果maven的sonar和sonar服务器版本对不上,很有可能mysql中的表都不一样,这样maven 的sonar不能正确的将结果写到mysql,同样sonar服务器没法分析。