SonarQube Scanner安装配置

 

1、下载SonarQube Scanner安装包

在下载地址中挑选合适的安装包:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/,本文中使用的是sonar-scanner-2.8.zip

2、、安装及配置SonarQube Scanner

1)将下载的安装包解压到指定目录/export/data/tomcatRoot/scanner.jd.com($SCANNER_HOME

2)修改$SCANNER_HOME\conf\sonar-scanner.properties,如下,将红字替换成实际地址:

    #Configure here general information about the environment, such as SonarQube DB details for example
    #No information about specific project should appear here

    #----- Default SonarQube server
    sonar.host.url=http://localhost:9000 

注:如需修改JDK配置,修改$SCANNER_HOME\bin\sonar-runner文件,如下添加红字部分并将路径替换成实际路径

  #!/bin/sh
  #
  # SonarQube Runner Startup Script for Unix
  #
  # Optional ENV vars:
  #   SONAR_RUNNER_HOME - location of runner's installed home dir
  #   SONAR_RUNNER_OPTS - parameters passed to the Java VM when running Sonar
 ……
  #
  # The views and conclusions contained in the software and documentation are those of the
  # authors and should not be interpreted as representing official policies, either expressed
  # or implied, of Jon Disnard.
  JAVA_HOME=/export/servers/jdk1.7.0_79

3)设置环境变量,将bin文件加入到PATH中,如下红色字

cd 

vim .bash_profile

  # .bash_profile
  
  # Get the aliases and functions
  if [ -f ~/.bashrc ]; then
          . ~/.bashrc
  fi
  
  # User specific environment and startup programs
  SCANNER_HOME=/export/data/tomcatRoot/scanner.jd.com
  PATH=$PATH:$HOME/bin:$SCANNER_HOME/bin:.
  
  export PATH

4)校验配置,执行 sonar-scanner -h 命令,配置成功则展示如下:

  [root@localhost ~]# sonar-scanner -h
  INFO: 
  INFO: usage: sonar-runner [options]
  INFO: 
  INFO: Options:
  INFO:  -D,--define <arg>     Define property
  INFO:  -e,--errors           Produce execution error messages
  INFO:  -h,--help             Display help information
  INFO:  -v,--version          Display version information
  INFO:  -X,--debug            Produce execution debug output
  INFO:  -i,--interactive      Run interactively

3、配置被测项目,编辑sonar-project.properties,简单示例

  sonar.projectKey=org.sonarqube:example-it-jacoco-sonar-scanner

  #在SonarQube中展示的项目名称

  sonar.projectName=Java :: IT Coverage with JaCoCo :: SonarQube Scanner

  #在SonarQube中展示的版本号
  sonar.projectVersion=1.0
  
  #设置源代码的路径

 sonar.sources=/export/data/jenkins_home/workspace/sonarTest/it-jacoco-sonar-runner/src

  #设置字节码文件的路径
  sonar.binaries=/export/data/jenkins_home/workspace/sonarTest/it-jacoco-sonar-runner/classes
  sonar.language=java
  sonar.sourceEncoding=UTF-8
   
  #设置字报告存放的路径

 sonar.jacoco.itReportPath=/export/data/jenkins_home/workspace/sonarTest/it-jacoco-sonar-runner/reports/jacoco.exec

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值