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

Force javac instead of eclipse jdt as compiler #3007

Open
dawosch opened this issue Mar 19, 2023 · 3 comments
Open

Force javac instead of eclipse jdt as compiler #3007

dawosch opened this issue Mar 19, 2023 · 3 comments

Comments

@dawosch
Copy link

dawosch commented Mar 19, 2023

Hey, i'm using visual studio code with the "extension pack for java" extension.
Local i have installed java 17 (microsoft edition).
When i build my project with mvn -U clean install there will be classes generated and everything is fine.
But when i press shift + alt + B like your readme says, the code will be compiled with the eclipse jdt compiler, which seems to have problems with a dependecy called MapStruct.

Here is one file compiled with maven:
image

And here is the same file after pressing shift + alt + B:
image

Have a look at line 20.
When i start my project the java extension always recompile my code (with the eclipse compiler).
I disabled the auto build feature, but that changed nothing.
I also configured the runtimes for java 17 in hope that this version will be used for compiling my code, but it doesn't.

Here is a repository i created to reproduce the error: Repository

Here are also some settings of vscode:

{
  "java.configuration.updateBuildConfiguration": "automatic",
  "java.debug.settings.onBuildFailureProceed": true,
  "java.autobuild.enabled": false,
  "java.debug.settings.forceBuildBeforeLaunch": false,
  "java.jdt.ls.java.home": "C:\\Program Files\\Microsoft\\jdk-17.0.5.8-hotspot",
  "spring-boot.ls.java.home": "C:\\Program Files\\Microsoft\\jdk-17.0.5.8-hotspot",
  "java.compile.nullAnalysis.mode": "disabled",
  "java.configuration.runtimes": [
    {
      "name": "JavaSE-17",
      "path": "C:\\Program Files\\Microsoft\\jdk-17.0.5.8-hotspot",
      "default": true
    }
  ]
}
Environment
  • Operating System: Windows 10
  • JDK version: 17 (microsoft edition)
  • Visual Studio Code version: 1.76.2 (user setup)
  • Java extension version: 1.16.0
Steps To Reproduce
  1. Clone my test repository
  2. Run mvn -U clean install in the terminal
  3. Have a look at the generated source file TestMapperInterfaceImpl.java on line 20 (the setter)
  4. Press shift + alt + B to compile the project
  5. Have a look at the same file and you will notice that the setter is gone

Test repository: Link to the repository

Current Result

The eclipse jdt compiler messed something up so the generated files are not working.

Expected Result

The compiler i defined in the runtime settings should be used to compile my code.

Additional Informations

I also opened a issue at the microsoft/vscode-spring-dashboard extension because i first thought that the error is a problem ob this extension because i started my project over this extension. But i noticed that before it starts it will be recompiled.
Link to the issue of the spring boot extension

@snjeza
Copy link
Contributor

snjeza commented Mar 20, 2023

The issue is not related to eclipse jdt compiler.

@dawosch Could you try the following:

  • move the mapstruct-accessing-strategy module to a separate project
  • remove the mapstruct-accessing-strategy module from the com.example:parent project
  • install mapstruct-accessing-strategy
$ mvn clean install
  • open com.example:parent in VS Code or Eclipse
    TestMapperInterfaceImpl.java
package com.example.demo;

import javax.annotation.processing.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2023-03-20T01:40:43+0100",
    comments = "version: 1.5.3.Final, compiler: Eclipse JDT (IDE) 3.33.0.v20230218-1114, environment: Java 17.0.6 (Eclipse Adoptium)"
)
public class TestMapperInterfaceImpl implements TestMapperInterface {

    @Override
    public TestOutput toTestOutput(TestInput testInput) {
        if ( testInput == null ) {
            return null;
        }

        TestOutput testOutput = new TestOutput();

        testOutput.setValue( testInput.value() );

        return testOutput;
    }
}

See https://github.com/dawosch/vscode-java-extension-compiler-error/blob/main/app/pom.xml#L54

@dawosch
Copy link
Author

dawosch commented Mar 21, 2023

Thanks for your answere.
Yes this seems to work fine.

But i'm wondering why the language server needs to recompile all files.
When i have java installed and all settings point to my java version, i would expect that the language server will use this java version to.

@snjeza
Copy link
Contributor

snjeza commented Mar 22, 2023

The issue is related to the Java Service Provider. The provider configuration have to be packed into a jar file.
See https://docs.oracle.com/javase/tutorial/ext/basics/spi.html#package-in-jar-files

Note that the provider configuration file must be in the directory META-INF/services in the JAR file.

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

No branches or pull requests

3 participants