如何配置使mvn clean install自动触发sonar:sonar命令?
如何让
mvn clean install自动触发Sonar扫描? 当然可以实现这个需求!你只需要把Sonar Maven插件绑定到Maven构建生命周期的某个阶段,这样执行mvn clean install时就会自动触发sonar:sonar目标了。
通常我们会把它绑定到verify阶段——这个阶段刚好在测试执行完成之后、install阶段之前,能确保代码质量扫描是基于通过测试的代码来进行的。
下面是调整后的完整插件配置:
<plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <configuration> <skip>false</skip> </configuration> <executions> <execution> <id>sonar-scan</id> <phase>verify</phase> <goals> <goal>sonar</goal> </goals> </execution> </executions> </plugin>
几点补充说明:
- 如果你想绑定到其他生命周期阶段(比如
install阶段本身),只需要把<phase>标签里的verify改成对应的阶段名称就行。 - 如果某次构建想临时跳过Sonar扫描,可以在命令行加上参数:
mvn clean install -Dsonar.skip=true
内容的提问来源于stack exchange,提问作者vincent zhang
相关产品推荐
相关产品推荐

