1、父pom文件加入一下打包信息
放到最大的父pom文件内
<build> <plugins> <!--代码编译指定版本插件--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <target>1.8</target> <source>1.8</source> <encoding>UTF-8</encoding> <!--是否跳过单元测试 true跳过 false不跳过--> <skip>false</skip> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> <!--sonarqube扫描插件--> <plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.6.0.1398</version> </plugin> <!--java jacoco插件 配合sonarqube扫描使用 展示覆盖率--> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.8</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> <execution> <id>post-unit-test</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
2、本地maven settings文件加入sonar配置
<profiles> <profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <!-- Optional URL to server. Default value is http://localhost:9000 --> <sonar.host.url> 自己公司sonar地址 </sonar.host.url> <sonar.login>用户名</sonar.login> <sonar.password>密码</sonar.password> </properties> </profile> </profiles>
3、idea执行maven命令扫描sonar切推送远端sonar服务器
mvn clean install sonar:sonar