[英]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.我在 visual studio code 中使用 SonarLint 时遇到问题,我在 java 8 中使用这个插件非常好,但上周左右,Vscode 需要 java 11 作为最低 java 版本,当我更新这个时(我继续使用 java 8 为我的项目,根据Vscode可以使用两个版本),插件无法正常启动,这是一个错误:[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' [错误 - 16:57:02.683] java.lang.IllegalStateException:没有文件或目录匹配 '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.我知道 tools.jar 在 java 11 中不存在,我找不到 jar 来替换它或解决这个问题的方法。 I'm using the last version of sonarLint plugin 1.17.0我正在使用最新版本的 sonarLint 插件 1.17.0
Thanks for your answers.感谢您的回答。
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.要求 SonarLint 语言服务器需要一个 Java Runtime (JRE) 8 或 11。如果您的计算机上已经安装了一个,SonarLint 应该会自动找到并使用它。
If a suitable JRE cannot be found at the usual places, SonarLint will ask for your permission to download and manage its own version.如果在通常的地方找不到合适的 JRE,SonarLint 会征求您的许可以下载和管理自己的版本。
Finally, you can explicitly set the path where the JRE is installed using the sonarlint.ls.javaHome variable in VS Code settings.最后,您可以使用 VS Code 设置中的 sonarlint.ls.javaHome 变量显式设置 JRE 的安装路径。 For instance:例如:
{
"sonarlint.ls.javaHome": "C:\\Program Files\\Java\\jre-11.0.11"
}
On Windows, backslashes must be escaped, eg C:\Program Files\Java\jdk-11.0.11 On macOS, this path should include the /Contents/Home directory, eg /Library/Java/JavaVirtualMachines/jdk-11.0.11.jdk/Contents/Home在 Windows 上,必须转义反斜杠,例如 C:\Program Files\Java\jdk-11.0.11 在 macOS 上,此路径应包括 /Contents/Home 目录,例如 /Library/Java/Java.0.1Machines/jdk- jdk/目录/首页
To analyze JavaScript and TypeScript, SonarLint will also need Node.js.要分析 JavaScript 和 TypeScript,SonarLint 还需要 Node.js。
To enable the support for Java, you need the Language support for Java VSCode extension (version 0.56.0 or higher).要启用对 Java 的支持,您需要对 Java VSCode 扩展(版本 0.56.0 或更高版本)的语言支持。
The support for Apex and PL/SQL is only available together with SonarQube/SonarCloud.对 Apex 和 PL/SQL 的支持仅与 SonarQube/SonarCloud 一起提供。 For Apex, you'll also need the Salesforce Extension Pack VSCode extension.对于 Apex,您还需要 Salesforce 扩展包 VSCode 扩展。
Just a supplement to the answer, if you are using VSCode in Windows with WSL and installed the "Remote - WSL" extension.如果您在 Windows 中将 VSCode 与 WSL 一起使用并安装了“Remote - WSL”扩展,则只是对答案的补充。 You need to:你需要:
I tried it, and everything works well.我试过了,一切正常。 Could I verify somethings?我可以验证一些东西吗?
Do you set the settings.json file like this?你是这样设置settings.json文件的吗?
"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. java扩展依赖JDK11,我的项目依赖JDK8。 SonarLint works well too. SonarLint 也很好用。
And you can find this in the details page of SonarLint extension:您可以在 SonarLint 扩展的详细信息页面中找到它:
The SonarLint language server needs a Java Runtime (JRE) 8 or 11 . SonarLint 语言服务器需要 Java Runtime (JRE) 8 或 11 。 If one is already installed on your computer, SonarLint should automatically find and use it.如果您的计算机上已经安装了一个,SonarLint 应该会自动找到并使用它。 If a suitable JRE cannot be found at the usual places, SonarLint will ask for your permission to download and manage its own version.如果在通常的地方找不到合适的 JRE,SonarLint 会征求您的许可以下载和管理自己的版本。 Finally, you can explicitly set the path where the JRE is installed using the sonarlint.ls.javaHome variable in VS Code settings.最后,您可以使用 VS Code 设置中的 sonarlint.ls.javaHome 变量显式设置 JRE 的安装路径。 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.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.