28

I just finished posting this issue on SO about Lombok not generating my getters/setters. It turns out that it is conflicting with AspectJ. If I disable AspectJ, then the getters/setters are appropriately generated.

My guess is that the ajc compiler is not able to recognize lombok.

Are Lombok and AspectJ mutually exclusive? Do both technologies work together?

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Eric B.
  • 23,425
  • 50
  • 169
  • 316
  • [This site](https://weblogs.java.net/blog/fabriziogiudici/archive/2011/07/19/making-lombok-aspectj-and-maven-co-exist) could be useful. But you should more exactly describe what you're doing (Eclipse? Maven? Whatever?). – maaartinus Sep 18 '14 at 07:56
  • Thanks for the link; definitely a helpful suggestion, but for more complex AJ projects (ex: ITDs, member injection, interface implementation, etc), I don't envision the solution working. The proposed idea requires javac to run before ajc, but javac will fail on any files that make use of injected members/interfaces/etc, and consequently, there won't be any byte code for ajc to work with. At least, that's my theory; I still haven't tried it to be sure. – Eric B. Sep 18 '14 at 15:21
  • This helped when I had a problem adding aspectj-depended lib into project with lombok https://palesz.wordpress.com/2011/12/03/howto-maven-lombok-and-aspectj-together/ – Volodymyr Masliy Dec 20 '20 at 21:08

3 Answers3

9

The current answer according to AspectJ maintainer Andy Clement is that there are problems due to ECJ (Eclipse Compiler for Java) packages being included and renamed in the AspectJ compiler infrastructure.

For more information there is ongoing discussion between Eric B. and A. Clement on the AspectJ users mailing list:

Maybe we can close the issue here with this answer and report back when the problem is solved.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • 1
    Facing the similar issue. Did you got any working solution? – santhosh kumar Mar 19 '18 at 09:13
  • What was unclear about my answer? Did you even read the mailing list thread? – kriegaex Mar 19 '18 at 12:21
  • Cool and yes i have. I have actually asked @Eric B whether he got any solution(the question and the answer and mailing thread was on 2014). – santhosh kumar Mar 19 '18 at 12:33
  • @santhoshkumar Sorry for the delay in responding; I didn't see the notifications/thread. I never found a workable solution to the problem and ended up abandoning Lombok partly due to this limitation. I see that `@ChengT` posted a solution to this problem (AspectJ support is much more important to me). While I don't understand from a technical perspective why that should work, I would be tempted to try again in the future. – Eric B. Apr 04 '18 at 15:09
0

In 2022 - there's an answer to this on the AWS docs for the Lambda Powertools FAQ: https://awslabs.github.io/aws-lambda-powertools-java/FAQs/

To enable in-place weaving feature you need to use following aspectj-maven-plugin configuration:

<configuration>
    <forceAjcCompile>true</forceAjcCompile> 
    <sources/>
    <weaveDirectories>
        <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
    </weaveDirectories>
    ...
    <aspectLibraries>
        <aspectLibrary>
            <groupId>software.amazon.lambda</groupId>
            <artifactId>powertools-logging</artifactId>
        </aspectLibrary>
    </aspectLibraries>
</configuration>
shearn89
  • 798
  • 1
  • 9
  • 24
-2

Add Project Lombok as a dependency to the aspectj-maven-plugin as in:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.18</version>
    <scope>compile</scope>
</dependency>

For example:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.8</version>
        <dependencies>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
                <version>${aspectj.version}</version>
            </dependency>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjtools</artifactId>
                <version>${aspectj.version}</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.18</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
        <configuration>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <complianceLevel>${java.version}</complianceLevel>
            <encoding>${project.build.sourceEncoding}</encoding>
            <verbose>true</verbose>
            <privateScope>true</privateScope>
            <showWeaveInfo>true</showWeaveInfo>
            <outxml>true</outxml>
        </configuration>
        <executions>
            <execution>
                <phase>compile</phase>
                <goals>
                    <goal>compile</goal>
                    <goal>test-compile</goal>
                </goals>
                <configuration>
                    <aspectLibraries combine.self="override">
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                </configuration>
            </execution>
        </executions>
    </plugin>
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Cheng.T
  • 337
  • 1
  • 2
  • 9
  • I tried this and it didn't work for me. No changes in eclipse, and maven gave error from AJC: "You aren't using a compiler supported by lombok" – DavidA Jan 02 '19 at 22:57
  • Also unable to re-create a fix using this. – Maleki May 13 '20 at 20:15