SonarQube部署、运行常见错误解决

Sonar Error - Can not execute Sonar: You must install a plugin that supports the language ‘java’

在扫描项目时缺少扫描插件

检查路径 ${SONAR_HOME}/extensions/plugins 中是否有扫描插件

1. 有对应插件:则查看项目根路径 sonar-project.properties 配置文件

#must be unique in a given SonarQube instance
sonar.projectKey=ifc-handheld-webapp:scanner
#this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 5.1.2
sonar.projectName=ifc-handheld-webapp-scanner
sonar.projectVersion=1.0

#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=.

#Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8

#添加扫描语言
sonar.language=java
  • 添加扫描路径 sonar.sources=.
  • 添加扫描语言 sonar.language=java

2. 没有对应插件:将SonarQube服务初始化时在数据库创建的表全部删除或 删除数据库

重启服务

${SONAR_HOME}/bin/linux-x86-64/sonar.sh restart

这时会自动下载Java插件包

重新扫描

sonar-scanner
sonar-runner

插件配置(手动配置)

1. 配置js扫描插件为例
–> download
SonarQube部署、运行常见错误解决_第1张图片

2. 选择要下载的版本
SonarQube部署、运行常见错误解决_第2张图片

–> More versions
选择兼容版本
SonarQube部署、运行常见错误解决_第3张图片

下载地址: https://binaries.sonarsource.com/Distribution/sonar-javascript-plugin/

3. 添加插件
下载完成后将插件添加到 ${SONAR_HOME}/extensions/plugins目录下重启服务

Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ‘root’@‘localhost’ (using password: NO))

数据库拒绝连接:没有访问root用户的权限

如果使用MySQL数据库报这个错
1. 检查你创建数据库的sql如:

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;

CREATE USER 'sonar' IDENTIFIED BY 'sonar';

GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';

GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';

FLUSH PRIVILEGES;

2. 检查SonarQube配置文件 sonar.properties

用户名:sonar.jdbc.username=sonar
密码:sonar.jdbc.password=sonar
是否都为sonar

#数据库连接配置
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

#根据需求修改默认配置(默认9000端口)
#sonar.web.host=0.0.0.0
#sonar.web.context=

修改对应的jdbc.username与jdbc.password后

重启服务

${SONAR_HOME}/bin/linux-x86-64/sonar.sh restart

你可能感兴趣的:(Code,Review,java,Sonar)