我正在尝试让 SonarLint 插件在 Eclipse 中工作,但我不太走运。 更具体地说,在查看 Java 项目中的简单 Java 类时,我没有在“SonarLint On-the-fly”选项卡中看到任何检测到或突出显示的问题。
我使用以下软件。
操作系统:
Win 10 专业版 - 版本 1709
Java:
Java 版本“1.8.0_161”
Java(TM) SE 运行时环境(构建 1.8.0_161-b12)
Java HotSpot(TM) 64 位服务器 VM(构建 25.161-b12,混合模式)
eclipse :
版本:Oxygen.3 发布 (4.7.3)
Sonar 软件:
SonarLint Eclipse 插件:
org.sonarlint.eclipse.site-3.4.0 来源:https://www.sonarlint.org/eclipse/
SonarQube:
SonarQube 7.0 来源:https://www.sonarqube.org/downloads/
Sonar 扫描仪:
Sonar 扫描仪-3.1.0.1141 来源:https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner (Windows 64 位 - 链接)
我下载了SonarLint Eclipse插件,并成功安装到Eclipse中。我可以看到所有 SonarLint 选项卡和配置选项。
我下载并成功设置了 SonarQube 服务器(默认端口 9000 上的本地主机)。我还下载并设置了 Sonar Scanner。
我在 Eclipse 中创建了一个简单的 Java 项目,并在其中创建了一个 Java 类。我将 sonar-project.properties 文件添加到 Java 项目中。
sonar-project.properties
# must be unique in a given SonarQube instance
sonar.projectKey=sp
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=Simple Project
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
我的 Eclipse Java 项目如下所示:
我已成功设置我的项目绑定(bind)。
我可以毫无问题地启动 SonarQube 和登录。 我在 Windows 资源管理器中导航到我的“简单项目”所在的位置,并从那里打开了一个 Windows PowerShell。
我在成功扫描了 Simple Project 的 Windows PowerShell 中执行了命令 sonar-scanner,我可以在我的 SonarQube 服务器中看到结果。
所以到目前为止一切都很好。但是...... Eclipse 中没有任何问题的迹象。我在 Eclipse 中的 SonarLint On-the-fly 选项卡下没有看到任何问题。
我确实启用(选中)了“自动运行 SonarLint”,我还尝试通过右键单击文件 > SonarLint > 分析 来手动分析 App.java 文件。
我没有看到代码中或“SonarLint On-the-fly”选项卡中列出的任何问题。我一定是在某处错过了一步。谁能给我任何提示,说明如何在 Eclipse 中进行自动 SonarLint 问题检测?
谢谢!
最佳答案
事实证明,问题出在我的包命名约定中。 将包名称从“com.test.pckg”更改为“com.dev.pckg”解决了这个问题。
SonarLint Google Group 的 Jonathan 指出了以下内容:
Sonarlint in Eclipse has no way to see which files are tests and which are sources, so it uses a simple regexp, looking for the keyword test anywhere on the path of the file. From your screenshots, your file is in a folder named test, so only the test rules are applied to it.
Try to place the file in a package without the word test in the path, or check in Sonarlint options to see if you can edit the regexp.
来源:https://groups.google.com/forum/?pli=1#!topic/sonarlint/fw36A2H9AiI
关于java - SonarLint 插件在 Eclipse Oxygen 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49583392/