1.在maven的settings.xml配置 org.sonarsource.scanner.maven
<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.1.36:9000</sonar.host.url></properties></profile><profiles><pluginGroups><!-- pluginGroup| Specifies a further group identifier to use for plugin lookup.<pluginGroup>com.your.plugins</pluginGroup>--><!-- sonarqube --><pluginGroup>org.sonarsource.scanner.maven</pluginGroup></pluginGroups>
2.pom里面增加对接的配置
<!--指定Maven用什么编码来读取源码及文档 --><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>21</java.version>
<build><plugins><plugin><groupId>org.sonarsource.scanner.maven</groupId><artifactId>sonar-maven-plugin</artifactId><version>3.7.0.1746</version></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${java.version}</source><target>${java.version}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins></build><profiles><profile><id>sonar</id><activation><activeByDefault>true</activeByDefault></activation><properties><sonar.host.url>http://192.168.1.55:9000</sonar.host.url><sonar.projectKey>exam</sonar.projectKey><sonar.projectName>exam</sonar.projectName><sonar.projectVersion>1.0-SNAPSHOT</sonar.projectVersion><sonar.sourceEncoding>UTF-8</sonar.sourceEncoding><sonar.sources>src</sonar.sources><sonar.login>liurg</sonar.login><sonar.password>pas</sonar.password></properties></profile></profiles>