使用 SonarQube 分析 Maven 项目

1,494 阅读1分钟

step 1 : 需要在 Maven的 setting.xml 增加 sonarQuer:

<profiles> <profile> <id>sonar</id> <properties> <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar</sonar.jdbc.url> <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver> <sonar.jdbc.username>sonar</sonar.jdbc.username> <sonar.jdbc.password>sonar</sonar.jdbc.password> <sonar.host.url>http://localhost:9000</sonar.host.url> <!-- Sonar服务器访问地址 --> </properties> </profile> </profiles> <activeProfiles> <activeProfile>sonar</activeProfile> </activeProfiles>

step 2:找到需要检测代码的项目根目录,打开 cmd, 执行命令:mvn clean install sonar:sonar

注意是要把 sonar 服务器打开,否则无法检测 等待一段时间后,出现如下信息,说明检测完成:

step 3: 此时打开 sonar 页面,就可看到刚刚检查的结果:

到此结束!