Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler options in pom.xml are not obeyed #1709

Open
paulmedynski opened this issue Mar 7, 2024 · 4 comments
Open

Compiler options in pom.xml are not obeyed #1709

paulmedynski opened this issue Mar 7, 2024 · 4 comments

Comments

@paulmedynski
Copy link

VSCode with the RedHat Language Support for Java extension (which apparently uses M2E under the covers) does not obey all javac compiler options specified in the Maven pom.xml when compiling projects.

Environment

  • Operating System: Debian 12
  • JDK version: 21.0.1
  • Visual Studio Code version: 1.87.0
  • Java extension version: 1.29.2024030608
  • M2E version: Unknown - it's embedded in the Java extension.

Steps To Reproduce

  • Compile the sample project via mvn compile. Note that no errors or warnings are produced.
  • Open the sample project in VSCode and wait for the Java extension to build it. Note that 1 warning is produced.

Sample project:
https://github.com/paulmedynski/vscode-java-compiler-args

Current Result

VSCode produces compiler errors and warnings that are disabled in pom.xml.

Expected Result

VSCode compiles the project with the same compiler options specified in pom.xml.

Notes

Aso note that some other compiler options, such as --add-exports are also not obeyed. I'm not going to test every possible javac compiler option, but M2E should support them all, shouldn't it?

This issue was originally logged against the RedHat Language Support for Java extension here:

redhat-developer/vscode-java#3518

I was asked to open this issue against M2E by the extension maintainers.

@laeubi
Copy link
Member

laeubi commented Mar 7, 2024

I don't think the language server is responsible for compiling so I'm a bit confused what m2e (and Eclipse IDE extension" should do here...

@paulmedynski
Copy link
Author

paulmedynski commented Mar 7, 2024

I'm not sure either :) but I was directed here by the RedHat Language Support for VSCode extension maintainers.

Here's my scenario:

I have inherited a large legacy Java project, and I need to modernize it. When compiling with Java 21, thousands of warnings are produced. I can't address them all at once, so I have configured the compilation step in my pom.xml to supply the following javac options:

  • treat all warnings as errors (-Werror).
  • enable all Xlint warnings (-Xlint:all).
  • disable certain Xlint warnings that I can't address right now (for example -Xlint:-unchecked).
  • add some --add-exports arguments so the legacy code can access some internal APIs.

When compiling via mvn compile everything is happy - no warnings or errors.

When I open the project in VSCode, the Java Language Support extension (that uses M2E apparently?) ignores these compiler settings, and produces thousands of warnings/errors, making it nigh impossible to use the IDE language server features to work on the code.

IMO, whatever part of the extension is compiling/interpreting/linting/scanning the source code should be obeying the javac compiler options specified in the pom.xml. I don't know what bits and pieces under the covers are responsible for this behaviour, but I was directed here.

I hope that helps explain the situation.

@laeubi
Copy link
Member

laeubi commented Mar 7, 2024

I know that m2e passes options to jdt that the compiles the code in eclipse, maybe it works the same in vscode :-)
As @fbricon has directed you here, maybe he can give some insights or even propose a fix.

@fbricon
Copy link
Contributor

fbricon commented Mar 7, 2024

As I mentioned in the original issue, the problem comes from the Java configurator which doesn't map javac lint flags to their JDT equivalent. It currently only maps the serial error/warning

So more javac flags need to be handled there. PRs are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants