【发布时间】:2018-11-24 19:07:40
【问题描述】:
我正在使用 SonarQube 5.6.1 进行代码分析(使用 Spring Boot 和 Angular 编写的代码(使用 TypeScript))。 SonarQube Scanner for Maven 3.4.0.905 和 SonarTsPlugin 1.1.0 分别用于 Java 和 TypeScript 中的代码扫描。
在我的pom.xml 中,我设置了以下属性:
<frontend.directory>frontend</frontend.directory>
<sonar.host.url>http://sonarqube.some-url.local/</sonar.host.url>
<sonar.sources>src/main/java,${frontend.directory}/src/app,pom.xml</sonar.sources>
<sonar.exclusions>${frontend.directory}/node_modules/**</sonar.exclusions>
<sonar.tests>${frontend.directory}/src/app,src/test/java</sonar.tests>
<sonar.test.inclusions>**/*.spec.ts,src/test/java/**/*.java</sonar.test.inclusions>
<sonar.testExecutionReportPaths>${frontend.directory}/reports/ut_report.xml</sonar.testExecutionReportPaths>
<sonar.ts.coverage.lcovReportPath>${frontend.directory}/coverage/lcov.info</sonar.ts.coverage.lcovReportPath>
<sonar.ts.tslint.configPath>${frontend.directory}/tslint.json</sonar.ts.tslint.configPath>
<sonar.ts.tslint.nodePath>${frontend.directory}/node/node</sonar.ts.tslint.nodepath>
<sonar.ts.tslint.path>${frontend.directory}/node_modules/.bin/tslint</sonar.ts.tslint.path>
请注意,我将sonar.ts.tslint.nodePath 指向安装的本地节点,如下所示。
我使用frontend-maven-plugin 1.6 安装npm 和node:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>${frontend.directory}</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v10.1.0</nodeVersion>
<npmVersion>6.0.1</npmVersion>
</configuration>
</execution>
...
</executions>
</plugin>
我运行 ./mvnw sonar:sonar 来启动 SonarQube 扫描仪。但是,当 SonarTsPlugin 运行并继续运行 tslint 时,nodePath 将被忽略并使用全局节点。这会在我的 Jenkins 框中导致出现以下错误:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar (default-cli) on project nsgra-web: java.io.IOException: Cannot run program "node": error=2, No such file or directory -> [Help 1]
这对我来说很奇怪,因为节点是通过 frontend-maven-plugin 安装的,我指向的是 sonar.ts.tslint.nodePath 中的 node 二进制文件。
有人有什么见解吗?
【问题讨论】:
-
maven-frontend-plugin 是否在构建期间执行? maven-frontend-plugin 的默认阶段是
generate-resources,如果不调用,则实际上插件没有执行。尝试运行./mvnw package sonar:sonar -
还要确保您运行的 SonarTsPlugin 版本与 SonarQube 5.6.x 兼容。更高版本需要 6.7.x +。
-
@user944849 你能扩展一下吗? GitHub 在 requirements section 中有 5.6+ 版本。我找不到任何需要 6.7.x 的概念。
-
@AryanJ-NYC,plugin compatibility matrix 表明 SonarTS 1.1 版适用于 SonarQube 5.6 - 6.6,而至少 1.5+ 需要 6.7+。这是针对 SonarQube 提供的插件。
-
@AryanJ-NYC,我不确定。我认为首先开发了 SonarTsPlugin,然后 SonarQube 创建了他们自己的(SonarTs)。在你的鞋子里,我会确保只安装一个,并且安装的版本适合你正在运行的 SonarQube 版本。并确保您正在阅读正确的文档。有时当我搜索 SonarTs 时,会出现 SonarTsPlugin 的文档。可能非常混乱!
标签: maven typescript jenkins sonarqube sonarqube-scan