Sonar – ERROR: Failed to upload report – An error has occurred

最近在搭建Sonarqube的时候遇到一个问题,用Sonar-scanner扫描一个项目的时候出现了如下的错误

INFO: CPD calculation finished
INFO: Analysis report generated in 1439ms, dir size=17 MB
INFO: Analysis reports compressed in 1804ms, zip size=6 MB
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:59.037s
INFO: Final Memory: 37M/1535M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
ERROR: Failed to upload report - An error has occurred. Please contact your administrator
ERROR:
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.

然后按照提示加了-X去看debug的log,500错误?赶紧看了看 (sonar安装路径)\logs\web.log

Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (7138130 > 4194304). 
                              You can change this value on the server by setting the max_allowed_packet' variable.
	at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3681)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2512)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2079)
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2013)
	at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5104)
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1998)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:136)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:136)
	at org.sonar.db.ce.CeTaskInputDao.insert(CeTaskInputDao.java:53)
	... 48 common frames omitted

数据库?怎么数据库进来捣乱了,可怕!顺便吐槽下Sonarqube对DB的支持…

#----- MySQL >=5.6 && <8.0
# Support of MySQL is dropped in Data Center Editions and deprecated in all other editions

(冷静下来...)

问题找到了:Mysql参数设置问题
max_allowed_packet可以先再mysql用这个命令查下:mysql> SHOW VARIABLES LIKE ‘max_allowed_packet’;
需要修改的话,可以修改my.ini中的:max_allowed_packet = 128M(你想要的大小,这里我设置的是128M)

我的max_allowed_packet,原来默认是4M,改成128M之后问题解决了

PS:记得重启MySql, 还有Sonarqube!! (我没有重启Sonarqube,它还是认为是4M,再吐槽下)

PPS: 顺便提下在window下,Mysql 5.7的my.ini在C:\ProgramData\MySQL\MySQL Server 5.7这个路径

windows10操作系统下:
1. 由于我们使用MySql 时,需要修改mysql 的 my.ini 的配置文件。
2. 但是 mysql 5.7 的 my.ini 位置并不在 C:\Program Files\MySQL\MySQL Server 5.7 此目录的my-default.ini 并不是我们要的:
3. 如果安装在C盘的: 我们要进入 C:\ProgramData\MySQL\MySQL Server 5.7 此目录即可看到my.ini 此时你可以修改次配置啦!

加入讨论

电子邮件地址不会被公开。