SonarQube tutorial: Scan project code using maven plug-in

Three ways for sonar to scan code

insert image description here

Configure Mavensettings.xml

Add the following content. Note that pluginGroupsand profilesare both settingsfirst-level labels below.

<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.111.101:9000
            </sonar.host.url>
        </properties>
    </profile>
 </profiles>

Execute scan script

pom.xmlExecute the following script in the same level directory, and the results will be synchronized to SonarQubethe server.

There is no need to manually create a project on the sonarqube server in advance. After executing the following script, the project with the same name will be automatically sonarqubecreated on the server projectName.

mvn sonar:sonar   \
-Dsonar.projectKey=项目key,保证唯一 \
-Dsonar.projectName=可以与projectKey相同  \
-Dsonar.host.url=http://192.168.111.101:9000   \
-Dsonar.login=账号名 \
-Dsonar.password=密码 \
-Dsonar.java.sources=src  \
-Dsonar.java.binaries=target

Guess you like

Origin blog.csdn.net/a772304419/article/details/132754298