3、JMSN~Maven安装

本文详细介绍了如何配置Maven以使用阿里云仓库,并与Sonar集成进行代码质量检查。包括Maven的安装与环境配置,settings.xml的修改以指向阿里云maven仓库,以及如何设置Sonar的相关参数。

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服务器没法分析。

转载于:https://my.oschina.net/liufukin/blog/2221471

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值