简体   繁体   中英

SonarLint plugin not working in Eclipse Oxygen

I am trying to get SonarLint plugin working in Eclipse but I am not having much luck. More specifically, I don't see any issues detected or highlighted in the "SonarLint On-the-fly" tab when looking at a simple Java class in a Java project.

I use the following software.

OS :

Win 10 Pro - Version 1709

Java :

java version "1.8.0_161"

Java(TM) SE Runtime Environment (build 1.8.0_161-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

Eclipse :

Version: Oxygen.3 Release (4.7.3)

Sonar software:

SonarLint Eclipse plugin :

org.sonarlint.eclipse.site-3.4.0 source: https://www.sonarlint.org/eclipse/

SonarQube :

SonarQube 7.0 source: https://www.sonarqube.org/downloads/

SonarScanner :

sonar-scanner-3.1.0.1141 source: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner (Windows 64 bit - link)

I downloaded the SonarLint Eclipse plugin and successfully installed it in Eclipse. I can see all the SonarLint tabs and configuration options.

I downloaded and successfully setup SonarQube server (localhost on the default port 9000). I also downloaded and set up Sonar Scanner.

I created a simple Java project in Eclipse and I created a Java class in it. I added the sonar-project.properties file to the Java project.

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

My Eclipse Java project looks like this:

在此输入图像描述

I have set up my project bindings successfully.

在此输入图像描述

I can start the SonarQube and login without issues. I navigated to the location of my "Simple Project" in Windows Explorer and opened a Windows PowerShell from there.

I executed the command sonar-scanner in the Windows PowerShell which successfully scanned the Simple Project and I can see the results in my SonarQube server.

在此输入图像描述

So all is good so far. BUT... There is no indication of issues in Eclipse. I don't see any issues under the SonarLint On-the-fly tab in Eclipse.

在此输入图像描述

I do have "Run SonarLint automatically" enabled (checked) and I also tried to manually analyze the App.java file by right-clicking on the file > SonarLint > Analyze .

I see no issues underlined in either the code or listed in the "SonarLint On-the-fly" tab. I must be missing a step somewhere. Could anyone please give me any tips how to get the automatic SonarLint issue detection working in Eclipse?

Thank you!

It turns out that the issue was in my package naming convention. Changing the package name from "com.test.pckg" to "com.dev.pckg" resolved the issue.

Jonathan in the SonarLint Google Group pointed out the following:

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.

source: https://groups.google.com/forum/?pli=1#!topic/sonarlint/fw36A2H9AiI

您可以在窗口 - >首选项 - >键入搜索文本文件“SonarLint”中更改首选项搜索,第一个选项可以删除下一个选项“测试文件正则表达式”,您可以在测试文件中使用它:) 在此处输入图像描述

I had offline tried to install sonarlint into Eclipse as my marketplace was not working. After successfully installing the plugin I was not able to see the feature enabled. it didn't reflect after installation. So I downloaded a new eclipse IDE and then I was able to install sonarlint through the marketplace. After that it got reflected in Project Code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM