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

Eclipse AJDT plugin + lombok don't work together #995

Open
xiaolongzuo opened this issue Jan 7, 2016 · 33 comments
Open

Eclipse AJDT plugin + lombok don't work together #995

xiaolongzuo opened this issue Jan 7, 2016 · 33 comments
Labels
aop documentation Addressing this item primarily involves writing docs / updating the website eclipse low-priority task There is a clear list of steps to take to address this item

Comments

@xiaolongzuo
Copy link

I use aspectJ compiler,then get error below(the @log4j is unavailable).Is there anyway to fixed?

[WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: sun/apple javac 1.6, ECJ
:

[ERROR] log cannot be resolved
D:\xxxxx.java:133
log.info("-------success:" + applicationId);

@zerkowsm
Copy link

👍

@NagoLazaro
Copy link

I am also getting the same error:

[ant:iajc] [warning] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
[ant:iajc] Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
[ant:iajc] Lombok supports: sun/apple javac 1.6, ECJ

Seems like the combination of AspectJ and Lombok is not working properly.

Has anyone achieved the compilation of an Application using both with Gradle/Maven?

@zybreak
Copy link

zybreak commented Feb 16, 2017

I'm having the same issue

@NicolasFelix
Copy link

Hi, erverybody.
I'm facing the same issue (lombok 1.16.16, maven aspectj plugin 1.10).
I've tried this, but without success.

Does anybody have an idea ?

@IFT8
Copy link

IFT8 commented May 9, 2017

Just do it

<build>
        <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <version>1.16.16.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>delombok</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <addOutputDirectory>false</addOutputDirectory>
                    <sourceDirectory>src/main/java</sourceDirectory>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.10</version>
                <configuration>
                    <complianceLevel>${java.version}</complianceLevel>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
 </plugins>
</build>

@laurentperez
Copy link

reviving this zombie thread since I have not found a way to solve this under the context : eclipse, intellij, maven cmdline. It either works in 2 out of 3, never in all 3 at once.

it looks like something is missing : how do you setup the plugin to use the delomboked folder ? obviously I've tried the but then it eithers breaks eclipse and/or intellij

@wrporter
Copy link

@laurentperez What were your solutions? I can't seem to get it to work on any 1 of the 3 options. I use IntelliJ and the command line.

@laurentperez
Copy link

@wrporter I found no solution, but I still believe a solution lies under the delomboked sources, I just couldn't find it. I'm under idea/cmdline too.
Workaround : remove lombok from the aspected classes, it's only sugar.

@wrporter
Copy link

wrporter commented Sep 1, 2017

@laurentperez My sample project now compiles after removing Lombok from a class that uses AspectJ. However, I can only get Lombok to work or AspectJ to work, not both. Do you have a solution for that?

@laurentperez
Copy link

@wrporter I got it working, see your PR wrporter/lombok-aspectj#1

@senthil-r
Copy link

I had this issue where aspecj and lombok together wasn't working. I had to move the aspectj pluin into Plugin management section and that resolved my issue. I have no idea what that really means but it did resolved my issue.

@cryptoe
Copy link

cryptoe commented Mar 23, 2018

I am using this
<build> <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory> <plugins> <plugin> <groupId>org.projectlombok</groupId> <artifactId>lombok-maven-plugin</artifactId> <version>1.16.16.0</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>delombok</goal> </goals> </execution> </executions> <configuration> <addOutputDirectory>false</addOutputDirectory> <sourceDirectory>src/main/java</sourceDirectory> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin</artifactId> <version>1.11</version> <configuration> <aspectLibraries> <aspectLibrary> <groupId>io.astefanutti.metrics.aspectj</groupId> <artifactId>metrics-aspectj</artifactId> </aspectLibrary> </aspectLibraries> <complianceLevel>1.8</complianceLevel> <source>1.8</source> <target>1.8</target> </configuration> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

with the properties
<properties> <project.build.java.target>1.8</project.build.java.target> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8 </project.build.sourceEncoding> </properties>

and with the dependencies
<dependency> <groupId>io.astefanutti.metrics.aspectj</groupId> <artifactId>metrics-aspectj</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.8.13</version> </dependency> <dependency> <groupId>io.dropwizard.metrics</groupId> <artifactId>metrics-annotation</artifactId> <version>3.2.2</version> </dependency>
Appologies for the formatting

@izogfif
Copy link

izogfif commented Sep 13, 2018

Beware: that <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory> might screw your IDE since it'll add that folder to source directory list and you might get "duplicate sources were found" issue.
This one works properly for me:

            <plugin>
                <!--
                <groupId>org.codehaus.mojo</groupId>
                Using snapshot build instead: https://github.com/mojohaus/aspectj-maven-plugin/issues/24#issuecomment-419077658
                -->
                <groupId>com.github.m50d</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.11.1</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>
                </dependencies>
                <configuration>
                    <complianceLevel>${maven.compiler.target}</complianceLevel>
                    <source>${maven.compiler.target}</source>
                    <target>${maven.compiler.target}</target>
                    <showWeaveInfo>true</showWeaveInfo>
                    <verbose>true</verbose>
                    <Xlint>ignore</Xlint>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <forceAjcCompile>true</forceAjcCompile>
                    <sources/><!-- this is important!-->
                    <weaveDirectories>
                        <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
                    </weaveDirectories>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

@symonk
Copy link

symonk commented Oct 1, 2018

any updates? this is so important :D

@aristotll
Copy link

any updates? this is so important :D

@symonk I don't think it is lombok's fault for incompatibility, but aspect's aj compiler.

@symonk
Copy link

symonk commented Oct 2, 2018

I've moved to google guice for some AOP and it seems to work great with lombok

@imosapatryk
Copy link

+1

@WillingAC
Copy link

I had this issue where aspecj and lombok together wasn't working. I had to move the aspectj pluin into Plugin management section and that resolved my issue. I have no idea what that really means but it did resolved my issue.

@senthil-r The pluginManagement element in pom.xml is intended to configure project builds that inherit from this one, but not declaring an to-be-used plugin in current projects and its dependent projects. In another word, you are just not using AspectJ compiler.

@Ghilteras
Copy link

google guice

@symonk could you share the pom.xml code to weave at compile time using google guice?

@bergerst
Copy link

bergerst commented Mar 6, 2019

Posting again with a different user:

Workaround for all Eclipse users struggling with AJDT (AspectJ plugin) interfering with Lombok:

The AspectJ maven plugin configuration provided by @izogfif solves build errors during maven builds, but AJDT still uses a different configuration and compiles the files in src/main/java using ajc instead of doing bytecode (class file) weaving like the aspectj-maven-plugin with the configuration from above.

I have found no way to tell AJDT to not compile the source files without breaking the classpath of the Eclipse project. You can specify the locations of additional classes and jar files to inject your aspects into, but you can't remove the default locations of src/main/java and src/test/java.

What I did instead to solve the problem was:

  1. Remove AJDT from the project my doing right click on project -> AspectJ -> Remove
  2. Convert the .aj files to Java classes containing the same logic using annotations (Sadly there aren't any extensive tutorials on how to do annotation-based aspects)
  3. Test the annotated class by doing maven command line builds until the aspectj-maven-plugin does not complain about your aspect class anymore
  4. If you have a lifecycle mapping (under <pluginManagement><plugins>) with <ignore></ignore> for the aspectj-maven-plugin, change it to <execute /> so Aspects work in the Eclipse debugger and JUnit tests

For me this workaround was acceptable because I had only one small aspect in .aj form in my project and seeing the AspectJ indicators provided by AJDT isn't that useful.

Also, no matter what the internet says, you don't (!!) need any extra configuration files or Spring to make AspectJ annotations work. You can do compile-time and bytecode weaving the same way as with .aj files.

The majority of the search results for "AspectJ annotations bytecode weaving" lead to guides for compile-time weaving with AspectJ annotations, load-time weaving with Spring, or bytecode weaving with .aj files.

@jhswedeveloper
Copy link

@bergerst Hi could you please share the changes made in pom.xml?

@bergerst
Copy link

@junhuhdev The pom.xml uses the snippet provided by izogfif above. It works as long as you don't build with Eclipse.

I only made changes by converting the .aj files into annotated Aspect classes and removing AJDT so Eclipse can compile the projects.

@jhswedeveloper
Copy link

@bergerst Ok, I have similar setup using annotated aspect classes. Tests and builds are running fine, but I am getting this during build.

[INFO] --- aspectj-maven-plugin:1.10:test-compile (default) @  ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]

[WARNING] You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.BatchProcessingEnvImpl
Lombok supports: sun/apple javac 1.6, ECJ
	<unknown source file>:<no line information>

Should this just be ignored? Also are you using lombok-maven-plugin?

@Ghilteras
Copy link

Ghilteras commented Mar 21, 2019

I'm actually getting this on IntelliJ with lombok and jcabi-aspects together

SLF4J: The following loggers will not work becasue they were created
SLF4J: during the default configuration phase of the underlying logging system.
SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger

@bergerst
Copy link

@junhuhdev That probably means that AJDT is still activated for your project. Right click on the project -> AspectJ -> Remove AspectJ capability. Then it should work.

If it still doesn't work, is Lombok set as java agent in the eclipse.ini file?

@kkman2008
Copy link

kkman2008 commented Jan 24, 2020

What's conclusion? How to make Lombok work with aspectJ?
It could work, please look the below link as reference:
https://palesz.wordpress.com/2011/12/03/howto-maven-lombok-and-aspectj-together/

@bergerst
Copy link

@kkman2008 See #995 (comment) together with my guide in #995 (comment)

@bergerst
Copy link

bergerst commented Dec 3, 2020

@cooligc The question is already answered by me, the only thing missing is either:

  • Finding and documenting a better solution
  • Officially documenting my solution

But since it's been 1 1/2 years since my comment, I don't think that anyone else will come up with a better solution.

@rzwitserloot
Copy link
Collaborator

@bergerst It sounds like your guide is mostly a setup to eliminate aspectj from your sourcebase, but I get the feeling I'm not fully grokking this guide.

I'm open for adding something to the 'setup' section of the website at least, possibly improve that error folks are getting so that it mentions that link.

@bergerst
Copy link

bergerst commented Dec 9, 2020

@rzwitserloot No, you misunderstood.

The steps by izogfif probably work for IntelliJ IDEA, but Eclipse has an AspectJ plugin called AJDT which interferes with Lombok. Necessary code changes in the AJDT plugin will never happen since its community is dead, so disabling AJDT is the only option.

My additional steps do exactly that. After that, Eclipse will produce lots of compiler errors because it doesn't know how to handle AspectJ-.java files if the project uses those.

However, AspectJ can be added to a project in 2 ways:

  1. .java files
  2. .aj files

The capabilities are the same for both, but the format is different.

If you reproduce the .java content in .aj files, Eclipse doesn't know how to handle the .aj files and ignores them. However, the aspectj-maven-plugin will still use them during Eclipse maven builds.

@rzwitserloot
Copy link
Collaborator

rzwitserloot commented Dec 9, 2020

@bergerst ahhh - okay, now I'm starting to understand how it works!

Do you think it's worthwhile to add a full guide for this? I'm definitely thinking the error message should be better (and we can probably outright detect this scenario and write an error message accordingly, I'm sure the actual processor instance is a specific class from AJDT or something else unique to the AJDT scenario we can detect), but a guide to effectively turn eclipse into notepad.exe by taking your aspectJ-ified java code and ensuring eclipse treats them as plain text files (no highlighting, no compiling, no debugging, no HCR, no search tools, no refactor scripts, no outlines...) doesn't seem like something we actively want to suggest. That feels like curing a toothache by shooting the patient in the face: That's.. not much of a cure.

@projectlombok projectlombok deleted a comment from cooligc Sep 12, 2021
@rzwitserloot rzwitserloot added aop task There is a clear list of steps to take to address this item documentation Addressing this item primarily involves writing docs / updating the website labels Sep 12, 2021
@rzwitserloot
Copy link
Collaborator

STEPS:

  • Write a page in /website, probably under setup (entry Eclipse-AJDT perhaps?), with a link from the eclipse setup description. Include the full error message so people can easily find it when searching for the error. Include @bergerst's texts as basis for what this page should look like.
  • Someone needs to spend the time to install AJDT onto a machine with a git clone of lombok, run into this error, write some code that detects it, and update lombok to spit out a link to that page.

@Viyond
Copy link

Viyond commented Oct 20, 2022

Beware: that <sourceDirectory>${project.build.directory}/generated-sources/delombok</sourceDirectory> might screw your IDE since it'll add that folder to source directory list and you might get "duplicate sources were found" issue. This one works properly for me:

            <plugin>
                <!--
                <groupId>org.codehaus.mojo</groupId>
                Using snapshot build instead: https://github.com/mojohaus/aspectj-maven-plugin/issues/24#issuecomment-419077658
                -->
                <groupId>com.github.m50d</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.11.1</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>
                </dependencies>
                <configuration>
                    <complianceLevel>${maven.compiler.target}</complianceLevel>
                    <source>${maven.compiler.target}</source>
                    <target>${maven.compiler.target}</target>
                    <showWeaveInfo>true</showWeaveInfo>
                    <verbose>true</verbose>
                    <Xlint>ignore</Xlint>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <forceAjcCompile>true</forceAjcCompile>
                    <sources/><!-- this is important!-->
                    <weaveDirectories>
                        <weaveDirectory>${project.build.directory}/classes</weaveDirectory>
                    </weaveDirectories>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

nice, solved my problem, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aop documentation Addressing this item primarily involves writing docs / updating the website eclipse low-priority task There is a clear list of steps to take to address this item
Projects
None yet
Development

No branches or pull requests