sonar部署

sonar部署
  • 本地依赖:maven,jdk1.8,``
  • 安装部署
  • 下载sonarqube-6.3 .zip
  • 创建mysql数据库sonar及用户并授权
--创建用户
create user 'sonarqube'@'localhost' identified by 'mypassword';
-- 允许所有IP访问
create user 'sonarqube'@'%' identified by 'mypassword';  
flush privileges;

--创建数据库sonar,并赋予权限给用户sonarqube对sonar库的所有权限
create database sonar DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
grant all privileges on `sonar`.* to 'sonarqube'@'localhost' identified by 'mypassword';
grant all privileges on `sonar`.* to 'sonarqube'@'%' identified by 'mypassword';  
flush privileges;
  • 修改sonar配置文件(sonarqube-6.3\conf\sonar.properties)的数据库连接参数
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=sonarqube
sonar.jdbc.password=mypassword
  • 选择对应的操作系统型号启动操作。sonarqube-6.3\bin\windows-x86-64\StartSonar.bat
  • 启动成功后,测试(默认端口:9000,帐号/密码:admin/admin)。访问地址: http://localhost:9000

*** 注 *** :若出现闪退现象,请以管理员权限启动

  • 后续完善

安装sonar的window服务,以服务形式自动启动 自定义端口,修改配置文件sonarqube-6.3\conf\sonar.properties的属性值sonar.web.port=9000

整合maven,分析源码
  • 添加maven的setting.xml的配置,指向sonar的服务器地址
<settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  http://myserver:9000
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>
  • 配置项目的pom.xml文件
<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.sonarsource.scanner.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.2</version>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

参考 https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven

转载于:https://my.oschina.net/smatterer/blog/878658

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值