sonarqube 安装

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

安装需要的JVM环境要求:https://docs.sonarqube.org/latest/requirements/requirements/

文档:https://docs.sonarqube.org/latest/setup/overview/

OpenJDK 下载地址:http://openjdk.java.net/

安装OpenJDK

配置环境变量

1)配置JAVA_HOME

按Windows键+R键,出现运行窗口,在打开文件框中输入sysdm.cpl,点击确定,出现"系统信息"窗口。

在系统信息窗口依次点击,

系统信息窗口 =》高级 =》环境变量-》系统环境变量 , 注意:如果用户环境变量中有对应的环境变量设置,就在用户环境变量中添加。否则会优先读取用户环境,有可能找不到设置的环境变量。如果没有,在系统环境变量或用户环境哪一个都可以,系统环境变量是对所有用户生效的。

点击环境变量->新建->变量名JAVA_HOME,变量值JDK11的安装目录如C:Program FilesJavajdk11

sonarqube 安装

 2)配置Path环境变量

编辑Path变量

%JAVA_HOME%in;
这个变量插入最前面,注意要有分号和后面的变量间隔开。

注意:如果是win10系统,点击编辑后,要点击新建,值为%JAVA_HOME%in,win10系统中不用自己加冒包。

sonarqube 安装

效果如下图,

sonarqube 安装

3)验证是否安装成功

按windows键+R键,输入cmd,在打开的cmd窗口中输入java -version,安装成功提示如下:

Microsoft Windows [版本 10.0.17134.254]
(c) 2018 Microsoft Corporation。保留所有权利。
C:UsersAdministrator>java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

进到 sonarqube 解压后目录启动

# On Windows, execute:
C:sonarqubeinwindows-x86-64StartSonar.bat

登录本地网站

Log in to http://localhost:9000 using System Administrator credentials (login=admin, password=admin).

Analyzing a Project

Now that you're logged in to your local SonarQube instance, let's analyze a project:

  1. Click the Create new project button.
  2. When asked How do you want to create your project, select Manually.
  3. Give your project a Project key and a Display name and click the Set Up button.
  4. Under Provide a token, select Generate a token. Give your token a name, click the Generate button, and click Continue.
  5. Select your project's main language under Run analysis on your project, and follow the instructions to analyze your project. Here you'll download and execute a Scanner on your code (if you're using Maven or Gradle, the Scanner is automatically downloaded).

After successfully analyzing your code, you'll see your first analysis on SonarQube:

sonarqube 安装

还需要下载一个 sonarscanner-for-msbuild

https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/4.7.1.2311/sonar-scanner-msbuild-4.7.1.2311-net46.zip

需要把解压后的文件夹($install_directory)的路径添加到Path环境变量 

Add $install_directory to your PATH environment variable.

在PATH环境变量增加MSBuild,例如以下路径

C:WindowsMicrosoft.NETFramework64v4.0.30319

在的项目(sln)所在文件夹执行下面cmd命令

sonarqube 安装

 执行MsBuild.exe /t:Rebuild遇到报错

error MSB4019: 未找到导入的项目“C:Program Files (x86)MSBuildMicrosoftVisualStudiov12.0WebApplicationsMicrosoft.WebApplication.targets”。

 对于VS2019,正确的msbuild路径是C:\Program Files (x86)\Microsoft Visual Studio\2019\xxx\MSBuild\Current\Bin

所以修改在PATH环境变量MSBuild的路径

再次连续不间断的执行上面三条命令!

命令执行完如下图:

sonarqube 安装

 打开链接地址,最终效果如图:

sonarqube 安装