0

必须将我们的 maven 汇编器版本从 1.1.6 更新到 1.1.8。这是发生的唯一变化,现在 Sonar Maven 插件抛出了这个异常:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar 
    (default) on project ReconCoverage: java.util.ArrayList cannot be cast to java.lang.String ->

插件:

<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7</version>

<groupId>com.CORPNAME.raptor.build</groupId>
<artifactId>assembler-maven-plugin</artifactId>
<version>1.1.8</version>

我已经研究了大约一个星期,需要升级到这个汇编版本。没有其他团队在升级时遇到此问题,因为他们通过 jenkins 使用 Sonar。我正在使用 maven 插件,因为我们的项目有很多模块,并且它构建了覆盖结果以匹配它。

我查看了声纳的代码,它似乎发生在 sonar.batch.bootstrap.userproperties 中。我猜这是在传入声纳属性时发生的,例如:sonar.language、sonar.java.coveragePlugin、sonar.host.url 等。

覆盖属性示例:

<sonar.language>java</sonar.language>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.host.url>http://corp.sonar.url/</sonar.host.url>
<sonar.jdbc.url>jdbc:oracle:thin:@sonardb.corp.com:0000:sonardb</sonar.jdbc.url>
<sonar.jdbc.username>username</sonar.jdbc.username>
<sonar.jdbc.password>password</sonar.jdbc.password>
<sonar.jdbc.driver>oracle.jdbc.driver.OracelDriver</sonar.jdbc.driver>

根据声纳的代码,它通常通过 Map 获取属性。当这些字符串之一是数组列表时,它会引发此异常。无论如何配置我的属性,以便新的 maven 汇编程序正确传递这些值?

4

2 回答 2

1

我们在 3.1.1 版本中实施了一种解决方法,以规避注入非字符串属性的错误插件: https ://jira.sonarsource.com/browse/MSONAR-145

要使用它,只需更新 pom.xml 以使用:

<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
于 2016-09-14T06:45:25.243 回答
0

I finally found a workaround for this problem. I decided to not go the route of running Java 7 and then 8 to build the coverage report(check previous answers and comments). I'm sure that would work, but since none of our dev or CI machines had Java 8 environments set up, I tried a different route.

I was initially building the sonar report at the end of a mvn clean install through a module CoverageModule(which as the last module to build). The 1.1.8 java assembler version was throwing a fit when it built the project, and then ran the analysis.

I kept the module so that during a normal build, it would still run my ant task plugin to merge all of our module's Jacoco reports. I removed the sonar-maven-plugin from that module's pom and put it in the Project's aggregator module(parent of all modules). After running a full mvn clean install, I can run a mvn sonar:sonar and there appears to be no conflict with the new assembler version, and the old sonar version I was using.

于 2016-09-22T22:34:35.580 回答