1. 安裝包準備:
注意:不同版本之間是有兼容性問題的,可參考官方推薦版本
下載地址
sonarqube 版本:8.9.9.56886 說明:snoar服務器
sonar-pdfplugin 版本:3.x 說明:測試報告生成pdf插件
sonarscanner 版本:4.7.0.2747-windows 說明:掃描器
sonarqube-community-branch-plugin-1.8.0.jar 說明:指定掃描分支,不安裝,默認掃描master分支
java環(huán)境:jdk 11
2. 環(huán)境準備
配置系統(tǒng)環(huán)境變量
2.1 配置sonar-scanner
變量名:SONAR_SCANNER_HOME
變量值(安裝包所在位置):D:\work\soft\sonarqube\sonar-scanner-4.7.0.2747-windows
path新增:%SONAR_SCANNER_HOME%\bin
驗證:
$ sonar-scanner -v
INFO: Scanner configuration file: D:\work\soft\sonarqube\sonar-scanner-
4.7.0.2747-windows\bin\..\conf\sonar-scanner.properties
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.14.1 Eclipse Adoptium (64-bit)
INFO: Windows 10 10.0 amd64
2.2 配置sonarQube
- 配置jdk11的環(huán)境
變量名:JAVA_HOME11
變量值(安裝包所在位置):D:\work\soft\jdk-11.0.16.1_windows-x64_bin\jdk-11.0.16.1
path新增:%JAVA_HOME11%\bin
-
修改\conf\wrapper.conf配置文件
# Path to JVM executable. By default it must be available in PATH. # Can be an absolute path, for example: wrapper.java.command=D:/tools/jdk-11.0.16.1_windows-x64_bin/jdk-11.0.16.1/bin/java.exe #wrapper.java.command=java # # DO NOT EDIT THE FOLLOWING SECTIONS # #******************************************************************** # Wrapper Java #******************************************************************** wrapper.java.additional.1=-Dsonar.wrapped=true wrapper.java.additional.2=-Djava.awt.headless=true wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp wrapper.java.classpath.1=../../lib/sonar-application-8.9.9.56886.jar wrapper.java.classpath.2=../../lib/jsw/wrapper-3.2.3.jar wrapper.java.classpath.3=../../lib/sonar-shutdowner-8.9.9.56886.jar wrapper.java.library.path.1=./lib wrapper.app.parameter.1=org.sonar.application.App wrapper.java.initmemory=8 wrapper.java.maxmemory=32 #******************************************************************** # Wrapper Logs #******************************************************************** wrapper.console.format=PM wrapper.console.loglevel=INFO wrapper.logfile.format=M wrapper.logfile.loglevel=INFO wrapper.logfile.rollmode=DATE wrapper.logfile=../../logs/sonar.YYYYMMDD.log # Maximum size that the log file will be allowed to grow to before # the log is rolled. Size is specified in bytes. The default value # of 0, disables log rolling. May abbreviate with the 'k' (kb) or # 'm' (mb) suffix. For example: 10m = 10 megabytes. #wrapper.logfile.maxsize=0 # Maximum number of rolled log files which will be allowed before old # files are deleted. The default value of 0 implies no limit. wrapper.logfile.maxfiles=7 # Log Level for sys/event log output. (See docs for log levels) wrapper.syslog.loglevel=NONE #******************************************************************** # Wrapper Windows Properties #******************************************************************** # Title to use when running as a console wrapper.console.title=SonarQube # Disallow start of multiple instances of an application at the same time on Windows wrapper.single_invocation=true #******************************************************************** # Wrapper Windows NT/2000/XP Service Properties #******************************************************************** # WARNING - Do not modify any of these properties when an application # using this configuration file has been installed as a service. # Please uninstall the service before modifying this section. The # service can then be reinstalled. # Name of the service wrapper.ntservice.name=SonarQube # Display name of the service wrapper.ntservice.displayname=SonarQube # Description of the service wrapper.ntservice.description=SonarQube # Service dependencies. Add dependencies as needed starting from 1 wrapper.ntservice.dependency.1= # Mode in which the service is installed. AUTO_START or DEMAND_START wrapper.ntservice.starttype=AUTO_START # Allow the service to interact with the desktop. wrapper.ntservice.interactive=false #******************************************************************** # Forking Properties #******************************************************************** wrapper.disable_restarts=TRUE wrapper.ping.timeout=0 wrapper.shutdown.timeout=0 wrapper.jvm_exit.timeout=0
-
將下載的sonarqube-community-branch-plugin-1.8.0.jar插件放到\sonarqube-8.9.9.56886\extensions\plugins\目錄下
-
修改\conf\sonar.properties
# WEB SERVER
sonar.web.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.8.0.jar=web
sonar.ce.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin-1.8.0.jar=ce
-Dsonar.pdf.username=admin
-Dsonar.pdf.password=admin
3. 運行snoarQube
在\sonarqube-8.9.9.56886\bin\windows-x86-64\下,運行StartSonar.bat文件
第一次運行時會要求要修改密碼,根據(jù)提示修改密碼
賬號:admin
修改后密碼:admin123
4.sonarQube的配置項目
4.1創(chuàng)建項目
4.2訪問授權令牌
4.3生成令牌
4.4maven掃描運行方式
5.springcloud項目的配置
5.1添加配置文件sonar-project.properties
在被掃描的項目/模塊路徑下新增配置文件sonar-project.properties
配置文件內(nèi)容文章來源地址http://www.zghlxwxcb.cn/news/detail-818437.html
# must be unique in a given SonarQube instance
sonar.projectKey=test-service
# --- optional properties ---
# defaults to project key
#sonar.projectName=My project
sonar.projectName=test-service
# defaults to 'not provided'
#sonar.projectVersion=1.0
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Defaults to .
#sonar.sources=.
# 源代碼目錄,如果多個使用","分割 例如:mode1/src/main,mode2/src/main
sonar.sources=src/main/java
# 單元測試目錄,如果多個使用","分割 例如:mode1/src/test,mode2/src/test
sonar.tests=src/test/java
# java字節(jié)碼目錄
sonar.java.binaries=target/classes
# 單元測試報告目錄
#sonar.junit.reportsPath=target/surefire-reports
sonar.coverage.jacoco.xmlReportPaths=target/surefire-reports
# 代碼覆蓋率插件
sonar.java.coveragePlugin=jacoco
# jacoco.exec文件路徑
sonar.jacoco.reportPath=target/coverage-reports/jacoco.exec
# 忽略的目錄
#sonar.exclusions=*/src/test/**/*
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.login=admin
sonar.password=admin123
5.2pom.xml
在項目的父pom中添加依賴和插件依賴
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
</dependency>
<!-- Jacoco dependencies. -->
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 單元測試 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<plugin>
<!-- Configures the compiler. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<compilerArgs>
<arg>-Xlint</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- Code coverage plugin. -->
<!-- This sets up code coverage for the unit tests, the integration tests, -->
<!-- and the combined coverage of both. -->
<!-- After running a `mvn clean install`, open `target/site/jacoco-both/index.html` in a browser. -->
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<includes> <!--覆蓋率計算包含的類-->
<include>**/controller/**/*</include>
<include>**/service/**/*</include>
</includes>
<excludes> <!--排除像entity、配置等無單元測試意義的類。如有,在Sonar服務端也需要配合排除(Ignore Code Coverage: https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/#header-5)-->
<exclude>**/config/**/*</exclude>
<exclude>**/entity/**/*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
5.3執(zhí)行掃描
在sonar-project.properties文件所在位置執(zhí)行命令
mvn clean verify sonar:sonar -Dsonar.branch.name=develop
6. vue項目的配置
6.1 添加配置文件sonar-project.properties
在被掃描的項目/模塊路徑下新增配置文件sonar-project.properties文章來源:http://www.zghlxwxcb.cn/news/detail-818437.html
配置文件內(nèi)容
# must be unique in a given SonarQube instance
sonar.projectKey=web-service
# --- optional properties ---
# defaults to project key
#sonar.projectName=My project
sonar.projectName=web-service
# defaults to 'not provided'
#sonar.projectVersion=1.0
# 中文的字段需要用Unicode轉(zhuǎn)碼,展示到sonarqube的web中才不會亂碼
sonar.projectName=\u6d4b\u8bd5\u9879\u76ee
# 可用的配置項
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=./src
sonar.exclusions=/node_modules/
sonar.tests=./src
sonar.test.inclusions=**/*.spec.ts
# \u5FFD\u7565\u7684\u76EE\u5F55
#sonar.exclusions=*/src/test/**/*
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.login=admin
sonar.password=admin123
6.2 在sonar-project.properties文件所在位置執(zhí)行命令
sonar-scanner.bat -D"sonar.projectKey=web-service" -D"sonar.sources=." -D"sonar.host.url=http://localhost:9000" -D"sonar.login=admin" -D"sonar.branch.name=dev"
到了這里,關于sonar8.9版本 win10安裝使用手冊的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!