projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.92k stars 2.39k forks source link

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

Open xiaolongzuo opened 8 years ago

xiaolongzuo commented 8 years ago

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 commented 8 years ago

:+1:

NagoLazaro commented 8 years ago

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 commented 7 years ago

I'm having the same issue

NicolasFelix commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@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 commented 7 years ago

@wrporter I got it working, see your PR https://github.com/wrporter/lombok-aspectj/pull/1

senthil-r commented 6 years ago

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 commented 6 years ago

I am using this `

${project.build.directory}/generated-sources/delombok
    <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>

`

with the properties `

1.8 1.8 1.8 UTF-8 ` and with the dependencies ` io.astefanutti.metrics.aspectj metrics-aspectj 1.2.0 org.aspectj aspectjrt 1.8.13 io.dropwizard.metrics metrics-annotation 3.2.2 ` Appologies for the formatting
izogfif commented 6 years ago

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 commented 6 years ago

any updates? this is so important :D

aristotll commented 6 years ago

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 commented 6 years ago

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

imosapatryk commented 6 years ago

+1

WillingAC commented 5 years ago

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 commented 5 years ago

google guice

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

bergerst commented 5 years ago

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 commented 5 years ago

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

bergerst commented 5 years ago

@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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

@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 commented 4 years ago

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 commented 4 years ago

@kkman2008 See https://github.com/rzwitserloot/lombok/issues/995#issuecomment-421081283 together with my guide in https://github.com/rzwitserloot/lombok/issues/995#issuecomment-470108271

bergerst commented 3 years ago

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

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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.

rzwitserloot commented 3 years ago

STEPS:

Viyond commented 2 years ago

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.