'Error using SonarLint in Visual Studio Code (VsCode) and Java 11

I have a problem using SonarLint in visual studio code, I’ve been using very well this plugin in java 8 but arround last week, Vscode required java 11 as minimum java version and when I updated this (I keep using java 8 for my project, according to Vscode can use two versions), the plugin couldn’t start well, this is a error: [Error - 16:57:02.682] Analysis failed.

[Error - 16:57:02.683] java.lang.IllegalStateException: No files nor directories matching 'C:\Users\MyUser.m2\repository\com\sun\java\tools\11\tools-11.jar'

I know that tools.jar doesn’t exist in java 11 and I couldn’t find a jar to replace it or a way to solve this. I’m using the last version of sonarLint plugin 1.17.0

Thanks for your answers.



Solution 1:[1]

Requirements The SonarLint language server needs a Java Runtime (JRE) 8 or 11. If one is already installed on your computer, SonarLint should automatically find and use it.

If a suitable JRE cannot be found at the usual places, SonarLint will ask for your permission to download and manage its own version.

Finally, you can explicitly set the path where the JRE is installed using the sonarlint.ls.javaHome variable in VS Code settings. For instance:

{
    "sonarlint.ls.javaHome": "C:\\Program Files\\Java\\jre-11.0.11"
}

On Windows, backslashes must be escaped, e.g. C:\Program Files\Java\jdk-11.0.11 On macOS, this path should include the /Contents/Home directory, e.g /Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home

To analyze JavaScript and TypeScript, SonarLint will also need Node.js.

To enable the support for Java, you need the Language support for Java VSCode extension (version 0.56.0 or higher).

The support for Apex and PL/SQL is only available together with SonarQube/SonarCloud. For Apex, you'll also need the Salesforce Extension Pack VSCode extension.

Solution 2:[2]

Go to File-> Preferences -> Settings

Then search for sonarlint to bring up its settings

Copy-paste your java directory path here. In my case, I had to escape the backslashes.

enter image description here

Solution 3:[3]

I tried it, and everything works well. Could I verify somethings?

Do you set the settings.json file like this?

"java.home": "[Path to JDK]", // For example: D:\\workSoft\\JDK11

"java.configuration.runtimes": [  // This should be setted in User settings.json
    {
      "name": "JavaSE-11",
      "path": "[Path to JDK]"
    },
    {
      "name": "JavaSE-1.8",
      "path": "[Path to JDK]",
      "default": true
    }
  ]

I tried this, and everything works well. The java extension depends on JDK11 and my project depends on JDK8. SonarLint works well too.

And you can find this in the details page of SonarLint extension:

The SonarLint language server needs a Java Runtime (JRE) 8 or 11. If one is already installed on your computer, SonarLint should automatically find and use it. If a suitable JRE cannot be found at the usual places, SonarLint will ask for your permission to download and manage its own version. Finally, you can explicitly set the path where the JRE is installed using the sonarlint.ls.javaHome variable in VS Code settings. For instance:

{
    "sonarlint.ls.javaHome": "C:\\Program Files\\Java\\jre1.8.0_131"
    //I tried: both of "D:\\workSoft\\JDK8" and "D:\\workSoft\\JDK11" works.
}

Solution 4:[4]

Just a supplement to the answer, if you are using VSCode in Windows with WSL and installed the "Remote - WSL" extension. You need to:

  1. Install the JDK 11 in the WSL (e.g. Ubuntu)
  2. Update the settings.json under WSL /home/$username/.vscode-server/data/Machine to add the attriutte "sonarlint.ls.javaHome" and set the value to the home path of the JDK 11 in the WSL

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ε Г И І И О
Solution 3 Steven-MSFT
Solution 4 Raymond Chiu