'Lombok doesn't generate getters in hybris custom component

I have a custom hybris component. I added the following to the external-dependencies.xml

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.12</version>
            <scope>provided</scope>
        </dependency>

The Lombok plugin is installed, the annotation processing is enabled. In the IDE I see the generated methods, but when I run ant clean all I get errors.

For example here is a test class:

@Data
public class TestDto {

    private String prop;
}

Here is an example usage of it

        TestDto test = new TestDto();
        test.setProp("");
        test.getProp();

But the ant clean all says the following:

   [yjavac] Compiling 700 source files to /Users/myUser/Projects/MyProject/hybris/myComponent/classes
   [yjavac] ----------
   [yjavac] 1. ERROR in /Users/myUser/Projects/MyProject/hybris/myComponent/src/service/ExampleService.java (at line 65)
   [yjavac]     test.setProp("");
   [yjavac]          ^^^^^^^
   [yjavac] The method setProp(String) is undefined for the type TestDto
   [yjavac] ----------
   [yjavac] 2. ERROR in /Users/myUser/Projects/MyProject/hybris/myComponent/src/service/ExampleService.java (at line 66)
   [yjavac]     test.getProp();
   [yjavac]          ^^^^^^^
   [yjavac] The method getProp() is undefined for the type TestDto
   [yjavac] ----------
   [yjavac] 2 problems (2 errors)

BUILD FAILED

What am I missing?

Edit:

Here is the extensioninfo.xml. Maven is enabled.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<extensioninfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="extensioninfo.xsd">

    <extension abstractclassprefix="Generated" classprefix="MyPrefix" managername="MyManager"
               managersuperclass="de.hybris.platform.jalo.extension.Extension" name="myName" usemaven="true">
        <requires-extension name="Mycore"/>
        <requires-extension name="Mymqintegration"/>
        <requires-extension name="Mycommons"/>

        <coremodule generated="true" manager="com.example.api.jalo.MyManager"
                    packageroot="com.example.api"/>

        <webmodule jspcompile="false" webroot="/api"/>
    </extension>

</extensioninfo>

Edit2:

I found some tips about buildcallbacks.xml. I'm pretty new in hybris so I went trough some google -> copy -> paste -> try -> repeat cycle with the buildcallbacks but none of the found solution worked for me.

Here are some example I tried out without any success:

<target name="myModuleName_lombok">
    <javac srcdir="src" destdir="build" source="1.8">
           <classpath location="lib/lombok-1.18.12.jar"/>
    </javac>
    <echo message="     adding lombok"/>
</target>

<macrodef name="myExtName_before_build">
            <sequential>
                <addToClasspath classpathproperty="ext.MyExtName.classpath" path="${ext.MyExtname.path}/lib/lombok-1.18.12.jar"/>
            </sequential>
</macrodef>


Solution 1:[1]

I can't comment about Lombok, because I haven't used it in Hybris. But, the usual (and probably the proper way) to create Data or DTO classes is via the *-beans.xml.

You would normally have something like this instead:

<bean class="com.demo.facades.dto.TestDto">
    <property name="prop" type="String" />
</bean>

Reference:

Solution 2:[2]

The problem is in the way that the ant builds:

https://projectlombok.org/setup/ant

To implement this customization in ant create a file called buildcallbacks.xml in its extension:

https://wiki.hybris.com/x/YIVvAg

Solution 3:[3]

The problem with Hybris and Lombock is due to the compiler configuration from the properties file.

build.compiler=org.eclipse.jdt.core.JDTCompilerAdapter

if you change the property to

build.compiler=modern

the compilation process will pass fine. However, I can't guarantee that there will be no side effects.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 geffchang
Solution 2 emichels
Solution 3 Marian Vigenin