官方文档地址:官方文档

1.安装

我安装的是 sonarqube-10.2 需要jdk17的环境请先安装 jdk17

官方下载sonarqube-10.2安装包

直接解压、运行启动脚本

sonarqube-10.2.1.78527\bin\windows-x86-64\StartSonar.bat

sonarqube访问端口:9000

http://localhost:9000

2.项目改造

2.1 修改maven 的 settings.xml

<pluginGroups>
    <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
    <profile>
        <id>sonar</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <!-- 配置 Sonar Host地址,默认:http://localhost:9000 -->
            <sonar.host.url>
                http://localhost:9000
            </sonar.host.url>
        </properties>
    </profile>
</profiles>

2.2 修改 pom.xml

<plugins>
	<plugin>
	    <groupId>org.sonarsource.scanner.maven</groupId>
	    <artifactId>sonar-maven-plugin</artifactId>
	    <version>3.0.2</version>
	</plugin>
</plugins>

3.测试结果

3.1 测试

mvn sonar:sonar -Dsonar.login=admin -Dsonar.password=123456

3.2 结果

访问:http://localhost:9000

sonarqube 代码质量检测 部署_sonarqube

sonarqube 代码质量检测 部署_sonarqube_02

sonarqube 代码质量检测 部署_sonarqube_03