SonarQube(5.0.1) 环境的安装配置

 SonarQube 安装步骤

  1. 确定 JDK 和 MySQL 已经成功安装。
  2. 下载 SonarQube 及工具 SonarQube Runner,下载地址:http://www.sonarqube.org/downloads/
  3. 解压文件,将下载的 SonarQube 和 SonarQube Runner 解压到指定的目录。
  4. 添加环境变量:
    export SONAR_HOME=/home/huey/huey/sonar/sonarqube-5.0.1
    export SONAR_RUNNER_HOME=/home/huey/huey/sonar/sonar-runner-2.4
    export PATH=${SONAR_RUNNER_HOME}/bin:$PATH
  5. 数据库(MySQL)的配置:
    CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 
    CREATE USER 'sonar' IDENTIFIED BY 'sonar';
    GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
    GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
    FLUSH PRIVILEGES;

    在创建数据库与用户后, 修改 sonar.properties 属性文件:

    sonar.jdbc.username=sonar
    sonar.jdbc.password=sonar
    sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
    sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
  6. 根据数据库配置在 SonarQube Runner 的属性文件 sonar-runner.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
    
    #----- PostgreSQL
    #sonar.jdbc.url=jdbc:postgresql://localhost/sonar
    
    #----- MySQL
    sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
    
    #----- Oracle
    #sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE
    
    #----- Microsoft SQLServer
    #sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
    
    #----- Global database settings
    sonar.jdbc.username=sonar
    sonar.jdbc.password=sonar
    
    #----- Default source code encoding
    sonar.sourceEncoding=UTF-8
    
    #----- Security (when 'sonar.forceAuthentication' is set to 'true')
    sonar.login=admin
    sonar.password=admin
  7. 启动 SonarQube 服务(需要根据不同的平台选择相应的目录):
    sh sonar.sh start
  8. 至此,已经能够使用 SonarQube,访问 http://localhost:9000

客户端 SonarQube Runner 的使用

  1. 准备一个简单的示例项目 helloworld
    helloworld
    ├── bin
    │   └── com
    │       └── huey
    │           └── helloworld
    │               └── HelloWorld.class
    └── src
        └── com
            └── huey
                └── helloworld
                    └── HelloWorld.java
  2. 在项目配置跟路径下,创建配置文件 sonar-project.properties,SonarQube Runner 执行时会读取该文件。
    # required metadata
    sonar.projectKey=com.huey.helloworld
    sonar.projectName=Hello World
    sonar.projectVersion=1.0
    
    # path to source directories (required)
    sonar.sources=src
    
    # path to project binaries (optional), for example directory of Java bytecode
    sonar.binaries=bin
    
    # The value of the property must be the key of the language.
    sonar.language=java
    # Additional parameters
    sonar.my.property=value
  3. 在项目的根目录下,执行启动项目命令:
    sonar-runner
  4. 刷新 http://localhost:9000 ,项目 helloworld 已经启动:
原文地址:https://www.cnblogs.com/huey/p/4340850.html