java SonarQube 在主 AST 扫描期间“未找到类”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31528033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SonarQube "Class Not Found" during Main AST Scan
提问by wilson
My setup:
我的设置:
- Sonarqube 5.1.1
- Sonar-Maven Plugin 2.6 (also tried 2.7 and 3.6)
- JDK 1.7.0_51
- 声纳 5.1.1
- Sonar-Maven Plugin 2.6(也试过2.7和3.6)
- JDK 1.7.0_51
Example of the error:
错误示例:
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
According to this stackoverflow question, javax.annotation should be part of java 1.7 and up. Furthermore, I've tried putting it in the local maven repository but that didnt help.
根据这个stackoverflow question,javax.annotation 应该是 java 1.7 及更高版本的一部分。此外,我尝试将它放在本地 maven 存储库中,但这没有帮助。
So where is Sonar trying to find this package? Any help?!?
那么 Sonar 在哪里试图找到这个包呢?有什么帮助吗?!?
Update:
更新:
- I've tried modifying the sonar-maven-plugin to include a dependency on javax.annotation
- I've tried putting the dependency in my maven's settings.xml
- Upgrading my JDK to 1.8 has not helped.
- 我尝试修改 sonar-maven-plugin 以包含对 javax.annotation 的依赖
- 我试过将依赖项放在我的 Maven 的 settings.xml 中
- 将我的 JDK 升级到 1.8 没有帮助。
回答by Kraal
According to http://docs.oracle.com/javase/7/docs/api/index.html?javax/annotation/package-summary.htmlthe classes you expect are not part of JDK 7.
根据http://docs.oracle.com/javase/7/docs/api/index.html?javax/annotation/package-summary.html,您期望的类不是 JDK 7 的一部分。
The classes you're looking for are part of google JSR-305 implementation that was initiated here https://code.google.com/p/jsr-305/source/browse/trunk/ri/src/main/java/javax/annotation/Nullable.java?r=24and which moved to Findbugs:
您正在寻找的类是在此处启动的 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>
According to https://jcp.org/en/jsr/detail?id=305the JSR-305 is finished, but is in dormantstatus and has not been added to a JDK release yet.
根据https://jcp.org/en/jsr/detail?id=305,JSR-305已经完成,但处于休眠状态,尚未添加到 JDK 版本中。
Hope it helps.
希望能帮助到你。
回答by kosoant
To avoid adding SonarQube specific dependencies to your project, define a profile like this:
为避免向项目添加 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>
Then run your sonar analysis with a command like
然后使用类似的命令运行声纳分析
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.1:sonar -Psonarqube,sonarqube-dev
The sonarqube-dev profile is defined in my ~/.m2/settings.xml and it just specifies where my development environment SonarQube installation is
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>
What is achieved by all this?
这一切都取得了什么成果?
- sonarqube analysis specific dependencies don't pollute the project unnecessarily
- no sonarqube maven plugin defined in pom.xml. Each developer and Jenkins can use whatever sonar plugin and server installation they wish
- sonarqube 分析特定的依赖项不会不必要地污染项目
- pom.xml 中没有定义 sonarqube maven 插件。每个开发人员和 Jenkins 都可以使用他们希望的任何声纳插件和服务器安装
回答by Gerd Aschemann
This is more an addendum to the latest answer:
这更像是最新答案的附录:
I see similar problems and adding the google findbugs dependency to the project dependencies helps. Similar problems occured with joda convert like
我看到了类似的问题,将 google findbugs 依赖项添加到项目依赖项会有所帮助。joda convert 出现类似问题
[ERROR] [20:44:25.247] Class not found: org.joda.convert.ToString
[ERROR] [20:44:25.247] Class not found: org.joda.convert.ToString
Hence I also added
因此我还补充说
`<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-convert</artifactId>
<version>1.8.1</version>
<scope>provided</scope>
</dependency>`
But note, that I set the scope to provided to prevent these new dependencies to be added to a resulting war file.
但请注意,我将范围设置为提供以防止将这些新依赖项添加到生成的War文件中。
However, I still wonder why these errors occur since none of the analyzed classes seem to use these annotations?
但是,我仍然想知道为什么会发生这些错误,因为分析的类似乎都没有使用这些注释?