vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

When projects are built from maven tab, compilation results are not reflected in JAVA problems tab

Open palminha opened this issue 6 months ago • 19 comments

My project is composed by the following:

  • java, maven, spring boot
  • one main directory with several maven modules

Currently my settings are:

  "maven.executable.options": "-am",
  "java.configuration.updateBuildConfiguration": "automatic",
  "java.import.maven.enabled": true,
  "java.dependency.packagePresentation": "hierarchical",
  "java.dependency.syncWithFolderExplorer": true,
  "java.autobuild.enabled": false,
  "java.debug.settings.onBuildFailureProceed": true,

Since i disabled the java autobuild (following a suggestion from #4100 ), i build my project using maven (using the maven tab)

Image

When i build, i can see i can see the maven build logs in the terminal tab, but that outcome is not reflected in the problems tab.

Image

palminha avatar Jul 16 '25 08:07 palminha

Thanks for the explanation. This actually clears up the issue.

When you build your project through the VS Code CLI, or even using the Maven tab goals, you're basically doing the same thing : Calling mvn on the project. The Java extension has no way to listen to these calls and record any diagnostic information from them. It only does this for "Rebuild Projects" (manual), "Force Java Compilation" (manual), or the result of autobuild being enabled.

I guess a shorthand way to think about it is if the build is done by some external tool, the Java extension doesn't even know the build is happening, which is why there can be conflicts. If the Java extension is delegating the build to JDT-LS (language server), it can definitely collect diagnostics.

Some of this probably comes down to certain tooling wanting to give users the option to build, to see the output, but that's all there is.

rgrunber avatar Jul 16 '25 15:07 rgrunber

@rgrunber, hum... but here we're not talking about an external tool; Maven and Gradle are the standard build tools for Java community. Expectations are that the MAVEN plugin should not be considered as any other external tool (when compared to shell scripts or others).

This issue stems from another one: the build process using Java is not consistent with Maven (that was my starting point). There are a lot of issues coming back to these inconsistencies... example: #4101 #4107

palminha avatar Jul 16 '25 16:07 palminha

@rgrunber do you think it can be related with this one? #4080

palminha avatar Jul 16 '25 16:07 palminha

When you import a project, the build is handled by the Java extension. It uses either https://github.com/eclipse-buildship/buildship, or https://github.com/microsoft/vscode-gradle if it's installed. For Maven it uses https://github.com/eclipse-m2e/m2e-core . These are tools that do the build themselves and report the results so that the extension can update diagnostics. If you just call mvn/gradle in some terminal, the extension has no way of knowing what the result of that separate process was, or what diagnostics were emitted. There is no way to hook into a completely separate process that can be called at any time and retrieve its state. When you have the extension imported, the recommendation is to build it with one of the commands provided for this (eg. "Rebuild Projects", "Force Java Compilation").

rgrunber avatar Jul 16 '25 20:07 rgrunber

When you import a project, the build is handled by the Java extension. It uses either https://github.com/eclipse-buildship/buildship, or https://github.com/microsoft/vscode-gradle if it's installed. For Maven it uses https://github.com/eclipse-m2e/m2e-core . These are tools that do the build themselves and report the results so that the extension can update diagnostics. If you just call mvn/gradle in some terminal, the extension has no way of knowing what the result of that separate process was, or what diagnostics were emitted. There is no way to hook into a completely separate process that can be called at any time and retrieve its state. When you have the extension imported, the recommendation is to build it with one of the commands provided for this (eg. "Rebuild Projects", "Force Java Compilation").

just to clarify that i'm not calling maven from the terminal...i'm calling it from the UI tab, integrated in VSCode...

palminha avatar Jul 17 '25 08:07 palminha

why is the JAVA extension ignoring the MAVEN build files?! if the project is a maven or gradle the JAVA build should take it consideration and not trying to build on his own.

Sorry but this is standard way of how IntelliJ works

palminha avatar Jul 17 '25 08:07 palminha

This is the official extension pack for supporting JAVA, it is expected that these plugins work together and that the build process is consistent across

Image

palminha avatar Jul 17 '25 08:07 palminha

just to clarify that i'm not calling maven from the terminal...i'm calling it from the UI tab, integrated in VSCode...

Image

Whether you launch from a terminal or the Maven tab in the UI, it's just a user-space process. It just runs https://github.com/microsoft/vscode-maven/blob/f656b3b799e4d123fe85b66cbe3c80fe4588a561/src/utils/mavenUtils.ts#L161 , which is just using https://code.visualstudio.com/api/references/vscode-api#Terminal . There is no integration between that and the Java extension. If it generates files, the extension might react to that, but diagnostics aren't stored anywhere.

why is the JAVA extension ignoring the MAVEN build files?! if the project is a maven or gradle the JAVA build should take it consideration and not trying to build on his own. Sorry but this is standard way of how IntelliJ works

The only way to get diagnostics resulting from compilation is to compile the project. In the case of Maven, it is using https://github.com/eclipse-m2e/m2e-core which is using JDT's compiler implementation.

If I open a simple Maven project in IntelliJ and compile it in the embedded terminal, no errors are reported until the actual file is opened. The state of running mvn has no connection to known errors/warnings.

Image

rgrunber avatar Jul 17 '25 19:07 rgrunber

@rgrunber, thanks for following up.

From your message, I interpret that for having a fully integrated experience with Maven projects, there are two options:

  • We don't use the Maven plugin to compile
  • The maven plugin adopts m2m-core

Is that it?

palminha avatar Jul 18 '25 07:07 palminha

in intellij after importing a java/maven project there is no distinction if you compile via java or via maven... there is only one way to compile:

Image

palminha avatar Jul 18 '25 08:07 palminha

@rgrunber do you wanna share any ideas/feedback on how this situation can fixed?

palminha avatar Aug 29 '25 16:08 palminha

@maroony do you also face this problem?

palminha avatar Aug 29 '25 16:08 palminha

This is not a problem for me, because I have java autobuild enabled.

maroony avatar Sep 02 '25 10:09 maroony

This is not a problem for me, because I have java autobuild enabled.

autobuild enabled was also my starting point, but then i disabled it as per suggesed here by @rgrunber as a mitigation for this problem: https://github.com/redhat-developer/vscode-java/issues/4100

palminha avatar Sep 02 '25 10:09 palminha

@palminha the maven UI you're using is contributed by https://github.com/Microsoft/vscode-maven. So you're kinda barking up the wrong tree here. This extension does not get informed that the maven cli is being invoked by vscode-maven and therefore cannot show any diagnostics from that run. There is a way in VS Code to create diagnostics from cli output: ProblemMatchers. But it would be clearly up to vscode-maven to provide such matchers, as this extension uses a completely different approach to running maven builds, as @rgrunber has explained above.

tsmaeder avatar Sep 17 '25 16:09 tsmaeder

@palminha the maven UI you're using is contributed by https://github.com/Microsoft/vscode-maven. So you're kinda barking up the wrong tree here.

Nice... I was not aware that mutts were able to understand me... woof!

This extension does not get informed that the maven cli is being invoked by vscode-maven and therefore cannot show any diagnostics from that run. There is a way in VS Code to create diagnostics from cli output: ProblemMatchers. But it would be clearly up to vscode-maven to provide such matchers, as this extension uses a completely different approach to running maven builds, as @rgrunber has explained above.

Thanks for enlightening... I was not aware of that. With this explanation, I will be able to follow up on this topic with vscode-maven

Just as a final remark: On integrations or interactions "relationship" there are always two sides... ;)

Thanks, @tsmaeder for the clarification.

palminha avatar Sep 18 '25 11:09 palminha

Thanks for enlightening... I was not aware of that. With this explanation, I will be able to follow up on this topic with vscode-maven

From the point of view of the user, it's impossible to distinguish between the different extensions 🤷 That's a hard problem to solve.

tsmaeder avatar Sep 18 '25 13:09 tsmaeder

@tsmaeder @rgrunber contributed here: https://github.com/microsoft/vscode-maven/pull/1099

But I don't see a lot of activity in that project...

palminha avatar Sep 28 '25 00:09 palminha

a PR is already in review here: https://github.com/microsoft/vscode-maven/pull/1099

palminha avatar Oct 12 '25 09:10 palminha