Sonar因缺少代码属性的API不兼容而失败

时间:2017-04-20 21:05:40

标签: java maven sonarqube sonarqube-scan sonar-maven-plugin

我的一位开发人员前几天创建了一个新的应用程序,现在我无法获得一个好的Sonar编译。我已经尝试了一些有关此类缺失代码错误的文档解决方法/解决方案,但没有找到正确的组合。该项目包括glassfish和glassfish-embedded-all jar,它们应该为javax-servlet提供实现。它们将进行范围测试。

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>4.1</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.servlet</artifactId>
    <version>3.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <scope>provided</scope>
</dependency>

我也尝试过这个,没有运气:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <classpathDependencyExcludes>
            <!-- exclude code absent api -->                                    
            <classpathDependencyExclude>javax:javaee-api</classpathDependencyExclude>                                
            <classpathDependencyExclude>javax:javaee-web-api</classpathDependencyExclude>
        </classpathDependencyExcludes>
    </configuration>
</plugin>

这是Maven 3.0.4的错误:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar (default-cli) on project Filters: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2:sonar: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/HttpServletRequestWrapper
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/root/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.0.2/sonar-maven-plugin-3.0.2.jar
[ERROR] urls[1] = file:/root/.m2/repository/org/apache/maven/shared/maven-dependency-tree/2.2/maven-dependency-tree-2.2.jar
[ERROR] urls[2] = file:/root/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[3] = file:/root/.m2/repository/org/eclipse/aether/aether-util/0.9.0.M2/aether-util-0.9.0.M2.jar
[ERROR] urls[4] = file:/root/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[5] = file:/root/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[6] = file:/root/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[7] = file:/root/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.6/sonar-scanner-api-2.6.jar
[ERROR] urls[8] = file:/root/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
[ERROR] urls[9] = file:/root/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar
[ERROR] urls[10] = file:/root/.m2/repository/com/google/code/findbugs/jsr305/2.0.3/jsr305-2.0.3.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>com.avaya.zephyr.services.sample_services.Authorization:Filters:3.4.0.0.0-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

项目的pom看起来很像另一个没有错误的类似项目。但是,它有一个警告:

Apr 20, 2017 4:52:16 PM net.sourceforge.pmd.lang.java.typeresolution.ClassTypeResolver visit
WARNING: Could not find class myBetterClass, due to: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/Application

我认为提供玻璃鱼嵌入式罐子应该可以解决这类问题。 (也许需要更新版本的玻璃鱼?)

1 个答案:

答案 0 :(得分:2)

您可以尝试通过尝试以下方法解决此问题:

  1. 将Maven更新为3.5.0以将Maven维持在最新版本。

  2. 您可以按照matrix here查看您使用的版本是否兼容。从日志中,您的构建使用older version of the plugin

      

    .scanner.maven:声纳-行家-插件:3.0.2

    尝试执行

    mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.3.0.603:sonar
    
  3. 确保您的排除标记在pom.xml的<properties>内标记为

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <sonar.host.url>http://www.example.com/</sonar.host.url>
        <sonar.exclusions>some/path/to/javax/javaee-api/**, some/path/to/javax:javaee-web-api</sonar.exclusions>
    </properties>