用于验证代码的 SonarQube Java 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24289704/
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 Java version used to verify code
提问by algiogia
How can I know against which version of Java SonarQube validates the code? Is it the version of the JVM? What then if my project is based on a different version?
我怎么知道哪个版本的 Java SonarQube 验证了代码?是JVM的版本吗?如果我的项目基于不同的版本怎么办?
采纳答案by Freddy - SonarSource Team
I do confirm that this property sonar.java.source is used only by the PMD tool. The SonarSource's Java analyser uses a superset grammar and so can analyse source files regardless of the Java version they comply to.
我确认此属性 sonar.java.source 仅由 PMD 工具使用。SonarSource 的 Java 分析器使用超集语法,因此可以分析源文件,而不管它们遵循哪个 Java 版本。
回答by edubriguenti
The default value is 1.5.
默认值为 1.5。
To set the appropriate version, you need to set sonar.java.source
property to tell PMD
which version of Java your source code complies to.
要设置适当的版本,您需要设置sonar.java.source
属性来说明PMD
您的源代码符合哪个 Java 版本。
Possible values: 1.4, 1.5 or 5, 1.6 or 6, 1.7 or 7. Since version 2.2 of the plugin, this property can also be set to 1.8 or 8.
可能的值:1.4、1.5 或 5、1.6 或 6、1.7 或 7。从插件的 2.2 版本开始,此属性也可以设置为 1.8 或 8。
If you're using the ant task, just add:
如果您使用的是ant task,只需添加:
<property name="sonar.java.source" value="${javaversion}"/>
If you're using the SonarRunner, just add the line below to the file <install_directory>/conf/sonar-runner.properties
:
如果您使用的是SonarRunner,只需将以下行添加到文件中<install_directory>/conf/sonar-runner.properties
:
sonar.java.source=1.5
回答by vsingh
From SonarCube 8.3 docs
来自 SonarCube 8.3 文档
When using SonarScanner to perform analyses of project, the property sonar.java.source can to be set manually in sonar-project.properties. Accepted formats are:
"1.X" (for instance 1.6 for java 6, 1.7 for java 7, 1.8 for java 8, etc.) "X" (for instance 7 for java 7, 8 for java 8, etc. )
使用 SonarScanner 进行项目分析时,可以在 sonar-project.properties 中手动设置属性 sonar.java.source。接受的格式是:
“1.X”(例如 1.6 表示 java 6、1.7 表示 java 7、1.8 表示 java 8 等)“X”(例如 7 表示 java 7、8 表示 java 8 等)
https://docs.sonarqube.org/latest/analysis/languages/java/
https://docs.sonarqube.org/latest/analysis/languages/java/
In our project, we use jdk 11. We have not set anything explicitly and it reads from pom.xml.
在我们的项目中,我们使用 jdk 11。我们没有明确设置任何内容,它从 pom.xml 中读取。
When running on the jenkins, I can see the output
在 jenkins 上运行时,我可以看到输出
[INFO] Configured Java source version (sonar.java.source): 11