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

[Question] How to enable annotation processing #453

Open
mbauhardt opened this issue Sep 13, 2023 · 2 comments
Open

[Question] How to enable annotation processing #453

mbauhardt opened this issue Sep 13, 2023 · 2 comments

Comments

@mbauhardt
Copy link

mbauhardt commented Sep 13, 2023

background
I want to emacs-lsp/lsp-java to compile/build a gradle based java project which uses annotation processing to generate source code.
I found https://github.com/emacs-lsp/lsp-java/blob/master/lsp-java.el#L1768 which let me hope that this feature is possible.

Steps to reproduce
So I updated my doom emacs lsp-java config to revision e78199d
and tried to build a small demo project https://github.com/mbauhardt/ecj-filer-exception without success
Because I'm new into emacs I'm pretty sure I do something wrong.

Final Question
Can someone help me and give me some hints how to enable my emacs config to support annotation processing to generate code?

thx.
marko

@ldeck
Copy link

ldeck commented Jan 24, 2025

@yyoncho I'm also trying to figure out how to enable annotation processing but with a maven based project.

I have a multi-module project, but have added a workspace folder for the module I'd like to work on in isolation.

When running lsp-java-build-project I see in the *lsp-logs* buffer errors indicating that annotation processing hasn't been considered.

e.g., for every spring component annotated with Lombok's @RequiredArgsConstructor coupled with a set of private final FooBarWiring foobarWiring I see in the lsp logs an entry like:

message: The blank final field foobarWiring may not have been initialized; code: 33554513; resource: /path/to/Component.java; line: 20

I can see the below files after for example running lsp-java-update-project-configurations and am unsure what configuration is missing? The build succeeds (with annotation processing occurring as intended) via maven, but not from lsp. There doesn't appear to be a configuration for lsp that would provide args to javac (if that's used) for the processor paths. Not sure if the jdt server has its own configuration that's required.

The configurations that appear relevant...

.factorypath

<factorypath>
    <factorypathentry kind="VARJAR" id="M2_REPO/org/projectlombok/lombok/1.18.34/lombok-1.18.34.jar" enabled="true" runInBatchMode="false"/>
    <factorypathentry kind="VARJAR" id="M2_REPO/org/mapstruct/mapstruct-processor/1.6.3/mapstruct-processor-1.6.3.jar" enabled="true" runInBatchMode="false"/>
</factorypath>

.project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
        <name>origin-sector-service</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
                <buildCommand>
                        <name>org.eclipse.jdt.core.javabuilder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
                <buildCommand>
                        <name>org.eclipse.m2e.core.maven2Builder</name>
                        <arguments>
                        </arguments>
                </buildCommand>
        </buildSpec>
        <natures>
                <nature>org.eclipse.jdt.core.javanature</nature>
                <nature>org.eclipse.m2e.core.maven2Nature</nature>
        </natures>
        <filteredResources>
                <filter>
                        <id>1717628456476</id>
                        <name></name>
                        <type>30</type>
                        <matcher>
                                <id>org.eclipse.core.resources.regexFilterMatcher</id>
                                <arguments>node_modules|.metadata|archetype-resources|META-INF/maven|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
                        </matcher>
                </filter>
        </filteredResources>
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
        <classpathentry kind="src" output="target/classes" path="src/main/java">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                        <attribute name="optional" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="target/test-classes" path="src/test/java">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                        <attribute name="test" value="true"/>
                        <attribute name="optional" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
                <attributes>
                        <attribute name="maven.pomderived" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" path="target/generated-sources/annotations">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                        <attribute name="ignore_optional_problems" value="true"/>
                        <attribute name="m2e-apt" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
                <attributes>
                        <attribute name="optional" value="true"/>
                        <attribute name="maven.pomderived" value="true"/>
                        <attribute name="ignore_optional_problems" value="true"/>
                        <attribute name="m2e-apt" value="true"/>
                        <attribute name="test" value="true"/>
                </attributes>
        </classpathentry>
        <classpathentry kind="output" path="target/classes"/>
</classpath>

@ldeck
Copy link

ldeck commented Jan 28, 2025

See #472

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

2 participants