为什么声纳:声纳之前需要 mvn 安装? [英] why sonar:sonar needs mvn install before?

查看:72
本文介绍了为什么声纳:声纳之前需要 mvn 安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档 http://docs.sonarqube.org/display/SONAR/Analyzing+with+Maven 说调用声纳的正确方法是:

official documentation http://docs.sonarqube.org/display/SONAR/Analyzing+with+Maven says that the proper way of invoking sonar is:

mvn clean install -DskipTests=true
mvn sonar:sonar

但没有说明原因.声纳是如何工作的?它需要编译类吗?那么为什么不只是 mvn clean compile 呢?还是需要jar文件?那么为什么不只是 mvn clean package 呢?声纳插件到底是什么?

but doesn't say why. how does sonar work? does it need compiled classes? so why not just mvn clean compile? or does it need a jar file? so why not just mvn clean package? what exactly does sonar plugin?

推荐答案

如果您满足某些要求,您可以将 SonarQube 作为单个 Maven 命令的一部分运行:

You can run SonarQube as part of a single Maven command if you meet some requirements:

  • 正如 Mithfindel 提到的,一些 SonarQube 插件需要分析 .class 文件.如果您在 SonarQube 之外运行单元测试,那么测试插件当然必须从 test 阶段读取输出.
  • 有集成测试吗?然后你需要在 integration-test 阶段之后运行.
  • 如果您想将 SonarQube 作为真正的质量门运行,那么您绝对必须在 deploy 阶段之前运行它.
  • As Mithfindel mentions, some SonarQube plugins need to analyze .class files. And if you run unit tests outside of SonarQube, then of course the testing plugins must read output from the test phase.
  • Got integration tests? Then you need to run after the integration-test phase.
  • If you want to run SonarQube as a true quality gate then you absolutely must run it before the deploy phase.

一种解决方案是在 package 阶段之后附加 SonarQube 以运行.然后,您可以通过简单的 clean installclean deploy 获得完整的构建.大多数人不会这样做,因为 SonarQube 很耗时,但是 4.0 中添加的增量模式并在即将到来的 4.2 中大大改进,解决了这个问题.

One solution is to just attach SonarQube to run after the package phase. Then you can get a full build with a simple clean install or clean deploy. Most people do not do this because SonarQube is time-consuming, but the incremental mode added in 4.0 and greatly improved in the upcoming 4.2 solves this.

就官方文档而言,说构建然后运行sonar:sonar"要容易得多,然后说打开你的POM,添加一个buildsonar-maven-plugin 的 元素,将其附加到 verify 等".

As far as the official documentation goes, it's a lot easier to say "build and then run sonar:sonar" then it is to say, "open your POM, add a build element for the sonar-maven-plugin, attach it to verify, etc".

一个警告.SonarQube 需要 Java 6,因此如果您针对 JDK 1.5(在大型组织中仍然很常见)进行构建,则必须在选择较新 JDK 的单独 Maven 调用中进行分析.我们使用自定义 Maven 构建包装器解决了这个问题.

One caveat. SonarQube requires Java 6, so if you're building against JDK 1.5 (still common in large organizations), the analysis will have to happen in a separate Maven invocation with a newer JDK selected. We solved this issue with custom Maven build wrapper.

这篇关于为什么声纳:声纳之前需要 mvn 安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆