redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 430 forks source link

Add feature if it doesn't already exists: Disable one Java project from building and reporting compiler errors in VsCode workspace having multiple Java Projects. #3749

Closed sairaghavak closed 1 week ago

sairaghavak commented 2 weeks ago

I have 2 java projects

"files.exclude": {
        "sb1-maven-java11": true,
 },

and also excluded it in files watcher

"files.watcherExclude": {
        "sb1-maven-java11": true,
 },

Also disabled under maven setting so that it's not scanned/recognized by maven view

"maven.excludedFolders":  [
  "sb1-maven-java11"
] 

But the problem is when I reload the Vscode window, the excluded project is still built during startup by Java language server and the compiler errors are reported under problems view.

Environment
Steps To Reproduce
  1. Open VsCode. Ensure that you have Redhat Java language server installed. Create 2 Java projects. Name it as A, B or as you wish.
  2. Add a bad code line in one of the project say project A just to have compiler error. Now, try to exclude A as mentioned in my issue description with maven settings and file exclude setting
Current Result

The compiler errors in project A are reported under problems view though that folder is excluded in project view and maven view.

Expected Result

I think it should be ignored by JavaLanguage Server from building that excluded project and stop reporting the problems(Compiler errors, Warnings) related to that project.

Or may be if there is any specific setting already to achieve this of ignoring a specific Java project from building could help resolve this issue.

snjeza commented 2 weeks ago

@sairaghavak You can try the following settings:

"java.import.exclusions": [
        "**/node_modules/**",
        "**/.metadata/**",
        "**/archetype-resources/**",
        "**/META-INF/maven/**",
        "**/sb1-maven-java11"

    ],

and clean the workspace directory:

sairaghavak commented 2 weeks ago

This works. Which folder does Java language server cleans?

jdneo commented 2 weeks ago

The cache folder for the language server is cleaned.

And there is another approach you can use when you want to import part of the maven sub-modules.

You can set the setting java.import.projectSelection to manual. And the trigger the command Java: import Java Projects into workspace, and select the folder you want to import. In this way, you do not need to set the "java.import.exclusions" in the workspace level.

rgrunber commented 1 week ago

Can this be closed now ?

If you ever did want to import the project but just suppress the errors/warnings, we also recently added :

java.diagnostic.filter: Specifies a list of file patterns for which matching documents should not have their diagnostics reported (eg. '**/Foo.java').

However, in this case excluding the prompt from import seems like the right aproach.

jdneo commented 1 week ago

Close and please leave comment if you have more query