SonarQube 源码调试环境搭建
2020-09-30 本文已影响0人
蓝笔头
下载并运行安装包
下载一个安装包 https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-6.7.7.zip 并解压。
image.png修改 conf
目录下的 sonar.properties
配置,添加远程调试配置选项。
#--------------------------------------------------------------------------------------------------
# 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
源码下载并运行远程调试
从 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
编译项目:
# 因为有一些类是通过 proto 文件定义的,所以需要先编译 proto 为 class 类。
mvn clean install -DskipTests
创建一个远程调试配置。
image.png在 org.sonar.server.app.WebServer
类的 main()
函数入口加上断点,运行远程调试配置。
调试环境搭建完毕!!!
参考
- SonarQube 安装、配置及 JaCoCo、Maven 集成
- Java远程调试 java -Xdebug各参数说明
- 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