下載并運行安裝包
下載一個安裝包 https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.7.zip 并解壓。

image.png
修改 conf 目錄下的 sonar.properties 配置,添加遠程調(diào)試配置選項。
#--------------------------------------------------------------------------------------------------
# WEB SERVER
# Web server is executed in a dedicated Java process. By default heap size is 512Mb.
# Use the following property to customize JVM options.
# Recommendations:
#
# The HotSpot Server VM is recommended. The property -server should be added if server mode
# is not enabled by default on your environment:
# http://docs.oracle.com/javase/8/docs/technotes/guides/vm/server-class.html
#
# Startup can be long if entropy source is short of entropy. Adding
# -Djava.security.egd=file:/dev/./urandom is an option to resolve the problem.
# See https://wiki.apache.org/tomcat/HowTo/FasterStartUp#Entropy_Source
#
sonar.web.javaOpts=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
運行 StartSonar.bat 命令:
E:\test\sonarqube-6.7.7\bin\windows-x86-64>StartSonar.bat
wrapper | --> Wrapper Started as Console
wrapper | Launching a JVM...
jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
jvm 1 |
jvm 1 | 2020.09.30 16:52:17 INFO app[][o.s.a.AppFileSystem] Cleaning or creating temp directory E:\test\sonarqube-6.7.7\temp
jvm 1 | 2020.09.30 16:52:17 INFO app[][o.s.a.es.EsSettings] Elasticsearch listening on /127.0.0.1:9001
jvm 1 | 2020.09.30 16:52:17 INFO app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='es', ipcIndex=1, logFilenamePrefix=es]] from [E:\test\sonarqube-6.7.7\elasticsearch]: C:\Program Files\Java\jdk1.8.0_221\jre\bin\java -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -Xms512m -Xmx512m -XX:+HeapDumpOnOutOfMemoryError -Delasticsearch -Des.path.home=E:\test\sonarqube-6.7.7\elasticsearch -cp lib/* org.elasticsearch.bootstrap.Elasticsearch -Epath.conf=E:\test\sonarqube-6.7.7\temp\conf\es
jvm 1 | 2020.09.30 16:52:17 INFO app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
jvm 1 | 2020.09.30 16:52:18 INFO app[][o.e.p.PluginsService] no modules loaded
jvm 1 | 2020.09.30 16:52:18 INFO app[][o.e.p.PluginsService] loaded plugin [org.elasticsearch.transport.Netty4Plugin]
jvm 1 | 2020.09.30 16:52:30 INFO app[][o.s.a.SchedulerImpl] Process[es] is up
jvm 1 | 2020.09.30 16:52:30 INFO app[][o.s.a.p.ProcessLauncherImpl] Launch process[[key='web', ipcIndex=2, logFilenamePrefix=web]] from [E:\test\sonarqube-6.7.7]: C:\Program Files\Java\jdk1.8.0_221\jre\bin\java -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.io.tmpdir=E:\test\sonarqube-6.7.7\temp -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -cp ./lib/common/*;./lib/server/*;E:\test\sonarqube-6.7.7\lib\jdbc\h2\h2-1.3.176.jar org.sonar.server.app.WebServer E:\test\sonarqube-6.7.7\temp\sq-process6188373622725236977properties
jvm 1 | Listening for transport dt_socket at address: 8000
源碼下載并運行遠程調(diào)試
從 GitHub 下載源碼:
# 下載源碼
meikai@DESKTOP-9TL46L9 MINGW64 /f/work/git_project/
git clone git@github.com:SonarSource/sonarqube.git
meikai@DESKTOP-9TL46L9 MINGW64 /f/work/git_project
$ cd sonarqube/
# 切換到 6.7.7 tag
meikai@DESKTOP-9TL46L9 MINGW64 /f/work/git_project/sonarqube (master)
$ git checkout 6.7.7 -f
# 刪除untracked files
meikai@DESKTOP-9TL46L9 MINGW64 /f/work/git_project/sonarqube ((6.7.7))
$ git clean -df
meikai@DESKTOP-9TL46L9 MINGW64 /f/work/git_project/sonarqube ((6.7.7))
$ git status
HEAD detached at 6.7.7
nothing to commit, working tree clean
用 IDEA 打開 sonarqube 項目。

當作 `Maven` 項目打開
用 maven 編譯項目:
# 因為有一些類是通過 proto 文件定義的,所以需要先編譯 proto 為 class 類。
mvn clean install -DskipTests
創(chuàng)建一個遠程調(diào)試配置。

image.png
在 org.sonar.server.app.WebServer 類的 main() 函數(shù)入口加上斷點,運行遠程調(diào)試配置。

image.png
調(diào)試環(huán)境搭建完畢?。。?/p>
參考
- SonarQube 安裝、配置及 JaCoCo、Maven 集成
- Java遠程調(diào)試 java -Xdebug各參數(shù)說明
- Git操作----刪除untracked files
- java 集成protobuf(maven項目)
- Docker 安裝 Mysql 5.7
拓展
sonar 配置mysql 連接報錯
sonar 版本 6.7
mysql 版本 8.0
mysql 換5.7版本可以成功
sonarqube建表語句中有mysql8中的關鍵字,所以建表總是失敗
#----- DEPRECATED
#----- MySQL >=5.6 && <8.0
# Support of MySQL is dropped in Data Center Editions and deprecated in all other editions
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported. It can not be changed.
配置文件里面寫了說不支持 8.0