How to avoid VS Code warning: "[myfile].java is a non-project file, only syntax errors are reported"

I got the same warning as well. It was simply because I had two Java (maven) projects in the same vscode workspace. Once I moved projectA out of the workspace, the warning for projectB is gone.

WorkspaceRoot
│   projectA
└───projectB

My current solution is to have one Java (Maven) project for one workspace, i.e, one Maven project per vscode workspace.

My guess is that vscode treats all Java projects inside the same workspace as as one project and hence, the projects interfering with each other.


I think I found the answer. The whole problem came up from loading not the direct project folder, but the parent folder, though the projects had been developed in their direct project folders from the start.

FOLDER1 (parent) contained

  • FolderA (direct project folder of java files)
  • FolderB (direct project folder of java files)

I have written the projects separately. But one time I opened the FOLDER1 in VS Code instead. That seems to have merged the 2 projects to just one project. After this, I changed back to opening only the FolderA/B and got the warnings that are reported in the question.

Now that I have opened FOLDER1 again and made both FolderA/B projects run without warnings (perhaps you might just comment out everything without fixing anything, but that is untested), opening the isolated FolderA/B projects threw no warnings either. Seems as if VS Code makes opening the parent folder the start of a new project which interferes with the child projects.

And the reason why I had a warning was a code error inside the other project's folder in the end (not important, but I had forgotten to load the local package needed for "FolderA" project at the start of some java file).

Whatever error I had, the warning was confusing, as I was only working on project "FolderB" which had nothing to do with "FolderA" and which had no code issue. This led to the strange effect that I got the warning of the "FolderA" project also in my "FolderB" project, because VS Code considered both as one project.