DEV Community

Sash HEY
Sash HEY

Posted on

How to configure Lombok, Delombok with Xtext?

Hello, I am working on a project that uses Lombok, Xtext, and QueryDSL, and I’m running into an issue. Specifically, I need Xtext to use delomboked files for further code generation, instead of the original files with Lombok annotations. The problem is that I see many errors in the console, such as “cannot find symbol” for the Q-classes and the classes generated by Xtext, which are used in my Java classes. The issue arises because these classes are generated after delombok runs, which is causing the errors during the delombok step.

The error in delombok state looks like this within INFO message, when I do mvn clean package from terminal or IDE:

[INFO] --- lombok:1.18.20.0:delombok (default) @ ART-Impl ---
/ART-Impl/src/main/java/com/core/domain/model/customer/CustomersRepository.java:3: error: package com.core.domain.model.customer.QCustomer does not exist
import static com.core.domain.model.customer.QCustomer.Constants.customer;
^
ART-Impl/src/main/java/com/core/domain/model/customer/CustomersRepository.java:18: error: cannot find symbol
import com.core.domain.composite.QCustomerComposite;

And I have pom like this :

    <plugin>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok-maven-plugin</artifactId>
            <version>1.18.20.0</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>delombok</goal>
                    </goals>
                    <configuration>
                        <addOutputDirectory>false</addOutputDirectory>
                        <outputDirectory>${delombok.dir}</outputDirectory>
                        <sourceDirectory>${src.dir}</sourceDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.eclipse.xtext</groupId>
            <artifactId>xtext-maven-plugin</artifactId>
            <configuration>
                <compilerSourceLevel>11</compilerSourceLevel>
                <compilerTargetLevel>11</compilerTargetLevel>
            </configuration>
            <executions>
                <execution>
                    <id>xtext.generate.sources</id>
                    <configuration>

                        <javaSourceRoots>
                            <sourceRoot>${delombok.dir}</sourceRoot>
                        </javaSourceRoots>
                        <sourceRoots>
                            <sourceRoot>${delombok.dir}</sourceRoot>
                            <sourceRoot>
                                ${project.basedir}/src/main/resources</sourceRoot>
                            <sourceRoot>
                                ${project.build.directory}/generated-sources/java</sourceRoot>
                        </sourceRoots>
                    </configuration>
                </execution>
                <execution>
                    <id>xtext.generate.test.sources</id>
                    <configuration>

                        <javaSourceRoots>
                            <sourceRoot>${delombok.dir}</sourceRoot>
                        </javaSourceRoots>
                        <sourceRoots>
                            <sourceRoot>
                                ${project.basedir}/src/main/resources</sourceRoot>
                            <sourceRoot>
                                ${project.build.directory}/generated-sources/java</sourceRoot>
                            <sourceRoot>
                                ${project.build.directory}/generated-test-sources/java</sourceRoot>
                        </sourceRoots>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            target/generated-sources/annotations</outputDirectory>
                        <processor>
                            com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Enter fullscreen mode Exit fullscreen mode

Can you help with how this should be correctly done? To not have errors in console.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay