docker

docker pull sonarqube:lts-alpine
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092  -e SONARQUBE_JDBC_USERNAME=sonar -e SONARQUBE_JDBC_PASSWORD=sonar sonarqube:lts-alpine

登录

http://192.168.99.100:9000/
admin/admin

maven配置

settings.xml

<settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  http://192.168.99.100:9000
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>

项目pom.xml

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

分析

mvn clean verify sonar:sonar -Dmaven.test.skip=true

查看结果

docs

03-05 19:44