Three ways for sonar to scan code
Configure Mavensettings.xml
Add the following content. Note that pluginGroups
and profiles
are both settings
first-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.xml
Execute the following script in the same level directory, and the results will be synchronized to SonarQube
the 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
sonarqube
created on the serverprojectName
.
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