主AST扫描期间SonarQube"未找到类"

wil*_*son 5 java maven sonarqube

我的设置:

  • Sonarqube 5.1.1
  • Sonar-Maven插件2.6(也试过2.7和3.6)
  • JDK 1.7.0_51

错误示例:

16:00:54 [INFO] [23:00:54.219] Sensor JavaSquidSensor
16:00:55 [INFO] [23:00:55.030] Java Main Files AST scan...
16:00:55 [INFO] [23:00:55.030] 1532 source files to be analyzed
16:00:58 [ERROR] [23:00:57.927] Class not found: javax.annotation.Nullable
16:00:58 [ERROR] [23:00:57.928] Class not found: javax.annotation.CheckReturnValue
16:00:58 [ERROR] [23:00:58.114] Class not found: javax.annotation.Nullable
Run Code Online (Sandbox Code Playgroud)

根据这个stackoverflow问题,javax.annotation应该是java 1.7及更高版本的一部分.此外,我已经尝试将它放在本地maven存储库中,但这没有帮助.

那么Sonar试图找到这个包裹在哪里?有什么帮助?!?

更新:

  • 我已经尝试修改sonar-maven-plugin以包含对javax.annotation的依赖
  • 我已经尝试将依赖项放在maven的settings.xml中
  • 将我的JDK升级到1.8并没有帮助.

Kra*_*aal 12

根据http://docs.oracle.com/javase/7/docs/api/index.html?javax/annotation/package-summary.html,您期望的类不是JDK 7的一部分.

您正在寻找的课程是在此处发布的Google JSR-305实施的一部分https://code.google.com/p/jsr-305/source/browse/trunk/ri/src/main/java/javax /annotation/Nullable.java?r=24并移动到Findbugs:

<dependency>
  <groupId>com.google.code.findbugs</groupId>
  <artifactId>jsr305</artifactId>
  <version>3.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

根据https://jcp.org/en/jsr/detail?id=305,JSR-305已完成,但处于休眠状态,尚未添加到JDK版本中.

希望能帮助到你.

  • 读到这个答案,我不确定解决方案是什么.我应该使用声纳maven插件配置添加此依赖项吗? (9认同)

kos*_*ant 9

为避免将SonarQube特定依赖项添加到项目中,请定义如下配置文件:

    <profile>
        <id>sonarqube</id>
        <dependencies>
            <dependency>
                <groupId>org.joda</groupId>
                <artifactId>joda-convert</artifactId>
                <version>1.2</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.findbugs</groupId>
                <artifactId>jsr305</artifactId>
                <version>3.0.0</version>
            </dependency>
        </dependencies>
    </profile>
Run Code Online (Sandbox Code Playgroud)

然后使用类似命令运行声纳分析

mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.1:sonar -Psonarqube,sonarqube-dev
Run Code Online (Sandbox Code Playgroud)

sonarqube-dev配置文件在我的〜/ .m2/settings.xml中定义,它只是指定我的开发环境SonarQube安装的位置

    <profile>
        <id>sonarqube-dev</id>
        <properties>
            <!-- no direct db connections in new sonar -->
            <sonar.host.url>
                http://localhost:9000/
            </sonar.host.url>
        </properties>
    </profile>
Run Code Online (Sandbox Code Playgroud)

这一切取得了什么成果?

  • sonarqube分析特定的依赖关系不会不必要地污染项目
  • 没有在pom.xml中定义的sonarqube maven插件.每个开发人员和Jenkins都可以使用他们希望的任何声纳插件和服务器安装