SonarQube代码质量分析

SonarQube 6.4 下载地址:https://www.sonarqube.org/downloads/

sonar-scanner2.5.1下载地址:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.1.zip

中文插件包sonar-l10n-zh-plugin-1.16.jar:https://github.com/SonarQubeCommunity/sonar-l10n-zh/releases

我是使用环境:windows   64bit 本地使用

1、开始使用:

  解压SonarQube6.4,sonar-scanner2.5.1

  插件包使用方法:直接拷贝到sonarqube下的extensions\plugins包下。

2、修改SonarQube6.4/conf/sonar.properties

  主要配置了用户名/密码和数据库等的相关信息

  sonar.login=admin
  sonar.password=admin

  sonar.jdbc.username=user
  sonar.jdbc.password=password
  sonar.jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

  sonar.web.port=9090#修改了下端口,默认的好像9000,我的居然冲突了,可能是开的程序太多,就直接换了一个

3、启动

  双击bin\windows-x86-64\StartSonar.bat

  在浏览器中打开http://localhost:9090就可以打开sonarqube窗口,如果配置了数据库打开可能会有点慢,稍等一会儿就行

4、添加项目

  打开sonar-scanner-2.5.1\conf\sonar-runner.properties文件

  配置mysql信息

  sonar.jdbc.username=user
  sonar.jdbc.password=password
  sonar.jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

  如果端口改了,就设置sonar.host.url=http://localhost:9090

5、配置环境变量

  name:SONAR_RUNNER_HOME,value:E:\test\sonar-scanner-2.5.1

  打开path,输入%SONAR_RUNNER_HOME%\bin,打开新的cmd窗口,输入sonar-runner -version显示版本表示设置成功

6、新建sonar-project.properties

复制代码

# must be unique in a given SonarQube instance
sonar.projectKey=my:project
# this is the name displayed in the SonarQube UI
sonar.projectName=apiautocore
sonar.projectVersion=1.0
 
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set. 
# If not set, SonarQube starts looking for source code from the directory containing 
# the sonar-project.properties file.
sonar.sources=src
 
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

复制代码

projectName是项目名字,sources是源文件所在的目录

7、设置成功后,启动sonarqube服务,并启动cmd

8、在cmd进入项目所在的根目录,输入命令:sonar-runner,分析成功。。。

9、打开http://localhost:9090/ 就可以看到代码分析结果。

-------------------------------------------------------------------------------------------------

如果你的环境已经配置过,则只需要在你的maven仓库的conf文件夹的settings.xml中的<settings>标签内添加<pluginGroups>
        <pluginGroup>

org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>

在<profiles>标签中添加

<profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <sonar.host.url>
                  http://192.168.0.161:9000
                </sonar.host.url>
            </properties>
        </profile>

在<activeProfiles>标签中添加<activeProfile>sonar</activeProfile>,

最后,Terminal中运行mvn sonar:sonar结束即可,打开  http://192.168.0.161:9000可看到结果

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值