如何在同一项目中为 java 和 javascript 配置 Sonarqube scanner



我一直在尝试为一个包含java模块(核心(和javascript模块(web(的Maven项目设置声纳扫描仪。

我能够扫描java覆盖数据并将其呈现在我的本地sonarqube服务器上,或者javascript,但不能两者兼而有之。

这是我的 sonar-project.properties 文件,其中 sonar.modules 属性可以有 4 个值之一:

### below: select just one of the 4 possible values for sonar.modules
sonar.modules = core --> get java coverage data
sonar.modules = web --> get javascript coverage data
sonar.modules = core,web --> get only java coverage data
sonar.modules = web,core --> get only java coverage data
sonar.sources=src
# javascript coverage report
web.sonar.exclusions=src/main/webapp/js/lib/**/*.js
web.sonar.javascript.lcov.reportPath = test-output/coverage/lcov.info
# java coverage report
core.sonar.java.binaries = target/classes
core.sonar.java.libraries = ../web/target/scheduler-web-3.5.0-SNAPSHOT/WEB-INF/lib
core.sonar.java.test.libraries = ../web/target/scheduler-web-3.5.0-SNAPSHOT/WEB-INF/lib
core.sonar.jacoco.reportPath = target/jacoco.exec
core.sonar.junit.reportsPath = target/surefire-reports
core.sonar.jacoco.reportMissing.force.zero = true

我的解决方案的关键,基于以下可接受的答案:

  • 顶级 POM 没有变化。

  • 添加到网络/pom.xml:

<properties>
    <sonar.javascript.lcov.reportPath>test-output/coverage/lcov.info</sonar.javascript.lcov.reportPath>
</properties>

基本上声纳不知道在哪里可以找到我的 lcov 文件。

您不应该将SonarQube扫描仪与专用sonar-project.properties文件一起使用来运行您的分析,而应该依靠Maven扫描仪。

要了解如何做到这一点,只需看看SonarQube本身(包含Java和JS(是如何分析的:

  • 转到其 GitHub 存储库
  • 看看 Web 模块的 server/sonar-web/pom.xml 文件,您会注意到:

  <properties>
    <!-- self-analysis -->
    <sonar.sources>src/main/js,src/main/less</sonar.sources>
    <sonar.tests>src/main/js</sonar.tests>
    <sonar.test.inclusions>src/main/js/**/__tests__/**</sonar.test.inclusions>
    <sonar.exclusions>src/main/js/libs/third-party/**/*,src/main/js/libs/require.js,src/main/js/**/__tests__/**</sonar.exclusions>
    <yarn.script>build</yarn.script>
</properties>

最新更新