I am running a build task in a java project in Visual Studio Code. The warning in the "PROBLEMS" tab:
[myfile].java is a non-project file, only
I got the same warning as well. It was simply because I had two Java projects in the same vscode workspace. Once I've moved projA out of the workspace, the warning for projB is gone.
WorkspaceRoot
│ projectA
└───projectB
At this point, I think the most likely solution is to have one Java (Maven) project for one workspace. Otherwise I guess vscode will treat they all as one project and they'll interfere with each other.
For me, removing the code folder in the C:\Users\yourHome\AppData\Roaming path solves the problem.
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
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.
Try cleaning the Java language server workspace:
Just worked for me.