Sonar本地使用手册for eclipse
Sonar-Scanner集成
主要是针对非maven项目
- 配置本地环境变量,path中增加%SONAR_SCANNER%\bin
- 修改%SONAR_SCANNER%\conf\sonar-runner.properties配置
#----- Default SonarQube server
sonar.host.url=http://10.102.16.91:9000
#----- Default source code encoding
sonar.sourceEncoding=UTF-8
- 在项目根目录增加配置文件sonar-project.properties,配置demo:
# must be unique in a given SonarQube instance
sonar.projectKey=com.wind.buy.lctime:lctime-parent
# this is the name displayed in the SonarQube UI
sonar.projectName=lctime-parent
sonar.projectVersion=1.0.0.1
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# The value of the property must be the key of the language.
sonar.language=java
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
# sonar.sources=src/main/java
sonar.modules=lctime-daemon,lctime-dal,lctime-integration,lctime-manager,lctime-website
# Properties can obviously be overriden for each module - just prefix them with the module ID
# lctime-daemon
lctime-daemon.sonar.projectName=lctime-daemon
lctime-daemon.sonar.sources=src/main/java
lctime-daemon.sonar.projectBaseDir=lctime-daemon
# lctime-dal
lctime-dal.sonar.projectName=lctime-dal
lctime-dal.sonar.sources=src/main/java
lctime-dal.sonar.projectBaseDir=lctime-dal
# lctime-integration
lctime-integration.sonar.projectName=lctime-integration
lctime-integration.sonar.sources=src/main/java
lctime-integration.sonar.projectBaseDir=lctime-integration
# lctime-manager
lctime-manager.sonar.projectName=lctime-manager
lctime-manager.sonar.sources=src/main/java
lctime-manager.sonar.projectBaseDir=lctime-manager
# lctime-website
lctime-website.sonar.projectName=lctime-website
lctime-website.sonar.sources=src/main/java
lctime-website.sonar.projectBaseDir=lctime-website
- 进入项目根目录,执行sonar-runner
集成maven
- 检查前提条件:
Maven 3.x
when SonarQube>=5.6 then maven-sonar-plugin=3.4.0.905 else maven-sonar-plugin=3.3.0.603
JDK 1.8
- 更新settings.xml文件(非必须)
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://10.102.16.91:9000</sonar.host.url>
</properties>
</profile>
</profiles>
- 执行分析命令:
1) mvn clean install -Dmaven.test.skip=true
2) mvn sonar:sonar -Dsonar.host.url= http://10.102.16.91:9000 -Dsonar.login=you token -Dsonar.branch=JFIRE_20180104_wdbyh
注:
1. sonar.login为用户的token,由sonar管理员或自己生成
2. 1)、2)两个步骤可以合并成一个,如果在settings.xml中已配置了sonar的地址,命令中可以不需要指定
Eclipse集成sonarLint
进入Help->Eclipse Marketplace,搜索“sonarLint”点安装即可:


浙公网安备 33010602011771号