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

expose annotation processor and remove hider enclosing class #973

Closed
rmannibucau opened this issue Nov 20, 2015 · 20 comments
Closed

expose annotation processor and remove hider enclosing class #973

rmannibucau opened this issue Nov 20, 2015 · 20 comments
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.

Comments

@rmannibucau
Copy link

When mixing annotation processors it is super important to be able to control their execution order, today it is almost impossible to do it properly with lombok cause of the hider class.

Is it possible to try to make it more open?

Side note: here is one conflicting annotation processor for instance mapstruct/mapstruct#510

@rzwitserloot
Copy link
Collaborator

It's not really hidden, it's just been renamed. You're looking for:

lombok.launch.AnnotationProcessorHider$AnnotationProcessor

If this is something more involved, then... we can't do much without more info on how @dave-lo fixed this issue. I don't even know what the issue is :/

parked for closing on January 1st 2016 without more feedback.

@rzwitserloot rzwitserloot added the parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these. label Nov 22, 2015
@rmannibucau
Copy link
Author

Well goal is to be able to order procs using -proc of javac. AnnotationProcessorHider doesnt allow it ATM AFAIK

@lsamayoa
Copy link

I am hitting with this issue too. The problem for me is that a corporate parent pom has the compiler plugin configured with <proc>none</proc> and adding a compile goal to the generate-source phase with <proc>only</proc> has not been an option.

@rspilker
Copy link
Collaborator

rspilker commented Dec 6, 2015

Can you tell us the platform you're using and the exact version of javac?

On linux you need to make sure the $ isn't interpreted. I could compile using

javac -processor 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor' -cp lombok.jar Test.java

@rmannibucau
Copy link
Author

1.8u45 and u60

@rspilker
Copy link
Collaborator

rspilker commented Dec 6, 2015

Windows, Linux, Mac. javac directly, Ant, Maven, Gradle?

Did you try my suggestion?

@rmannibucau
Copy link
Author

Linux or mac, mvn. Tried but never got a good ordering with other processors.

edit: mvn doesnt quote the processors names so can be the issue: https://issues.apache.org/jira/browse/MCOMPILER-256

@rspilker
Copy link
Collaborator

rspilker commented Dec 8, 2015

Could it be that Maven interpret the $ sign as a property? Try using the following:

lombok.launch.AnnotationProcessorHider&#36;AnnotationProcessor

@gunnarmorling
Copy link

Hi, as you know, I am working on MapStruct, an annotation processor for generating type-safe bean mappings. Users have been reporting issues when working with MapStruct and Lombok together in one project. These issues stem from the fact that MapStruct does not "see" the property accessors generated by Lombok, causing the MapStruct-generated mappers to be incomplete.

In general, MapStruct needs to be prepared for the fact that other processors may add property accessors by generating super-classes of the processed types (that's a pattern foreseen in the JSR 269 architecture). At the moment we don't support that yet, but we can do so by examining the super-type mirror(s) of processed types and if those have type kind ERROR, defer processing of the sub-types to a future round, by which the missing super-types will have been generated.

I hoped to do the same with Lombok-processed entities, but atm. I am lacking a way to decide whether a type has been fully amended or not (so MapStruct needs to defer its handling). So basically I am after something similar to checking the type kind of super-types as described above. I don't know how this could look like, but maybe you guys have any idea?

@rspilker
Copy link
Collaborator

I have an idea on how to fix this in general.

  1. Instead of using the processor discovery mechanism, the users need to specify the lombok annotation processor explicitly
  2. The user can instruct the lombok processor to invoke other processors. These are normal annotation processors.
  3. Lombok will steal the round and keeps running until all work is done
  4. Lombok invokes the other processors with all files
  5. If a processor generates new files, Lombok processes them first. Goto 3.

Possibly we can omit step 1 and 2 by using reflection to read and modify javac's internal structure. That would be the best for all users, but the Lombok processor should probably be invoked first, unless we can some serious hacking at class loading time.

What do you think? Might/would this work?

@5im5im
Copy link

5im5im commented Mar 13, 2016

Will there be a solution in the near future for this bug? Would be great if lombok would work with MapStruct out of the box. :-)

@wenerme
Copy link

wenerme commented May 26, 2016

Any progress here, lombok + mapstruct is a wonderful integration for Spring Boot.Like jhipster use mapstruct for dto, and spring boot suggest use lombok for entity and data model.Due to this issue, we can not use lombok + mapstruct, that'a awful.So, please.

@fitzyjoe
Copy link

I've been working around this issue by making a separate module for my lombok classes and compiling that module first. This stinks. I wish lombok and mapstruct were compatible with each other. After so long with no resolution, my team is trying to decide whether to rip out lombok or mapstruct so that we can consolidate the code.

@alexpetroaica
Copy link

Any updates on this? I really like both MapStruct and Lombok but will have to drop one of them as splitting the project into multiple modules is not an option...

@jchen9shc
Copy link

I am running similar issue when using lombok and Selma, Selma can't see the getter/setter lombok generates using @DaTa. Don't like the idea splitting the project into separate modules to make this work. Querydsl and lombok have similar issue, the solution is to set processors including lombok and querydsl annotation processors. Similar solution should be possible for lombok and Selma. Here is the link for Querydsl and lombok issue: https://github.com/ewerk/gradle-plugins/issues/59

@rzwitserloot
Copy link
Collaborator

Most of the chat and implementation talk on this problem has been held on issue mapstruct/mapstruct#510. We've got a solution in place and will release it soon.

@kevinmic
Copy link

kevinmic commented Mar 2, 2017

Your release 1.16.14 says "Lombok can now be used together with other annotation processors that are looking for lombok-generated methods, but only if lombok is the first annotation processor executed. The most commonly used annotation processor affected by this change is MapStruct; we've worked with the mapstruct team specifically to allow any order. Other annotation processors might follow the framework we've built to make this possible; point the authors of any such processor to us and we'll get it sorted"

I am attempting to make this upgrade on doanduyhai/Achilles#289 and am wondering if there is any documentation on what needs to be done to repeat what has been done here.

@rspilker
Copy link
Collaborator

rspilker commented Nov 6, 2017

Yes. We're implementing the AstModifyingAnnotationProcessor, and registered our implementation in META-INF/serviced. Any processor that needs to process AST's after lombok has done its work can query the isTypeComplete method to see is all word is done. If lombok modifies any file, a new processor round will be triggered, allowing other processors to query the method again, until it eventually will return true.

@rspilker rspilker closed this as completed Nov 6, 2017
@rspilker
Copy link
Collaborator

rspilker commented Nov 6, 2017

You can find an example in the mapstruct code.

@manoelcampos
Copy link

manoelcampos commented Apr 3, 2024

Hey guys, I know this is a very old and closed issue. Sorry if this is not the best place to start a new conversation.
I had the same issue with an annotation processing lib I've created, whose users may include Lombok too.
I tried to follow the links to see how processors order was defined in MapStruct code, but realized it's not that simple.

In the end, I found a straightforward solution to define the order in which annotation processors must run, without requiring any source code changes. I just added maven-processor-plugin to my pom.xml. There we include Lombok and other annotation processors as dependencies and define their execution order.

<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>5.0</version>
    <executions>
        <execution>
            <id>process</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <processors>
                    <!-- Defines the order in wich the annotation processors must execute.
                    Lombok needs to be the first one, because if you are using it,
                    the generated DTOs may include Lombok's annotations
                    and may need the code generated by it (such as getters and setters). -->
                    <processor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</processor>
                    <processor>io.github.manoelcampos.dtogen.DTOProcessor</processor>
                </processors>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.30</version>
        </dependency>
        <dependency>
            <groupId>io.github.manoelcampos</groupId>
            <artifactId>dtogen</artifactId>
            <version>1.0.7</version>
        </dependency>
    </dependencies>
</plugin>

You can check the entire pom.xml here. I hope this information helps other developers.

By the way, I've created a very cool library that uses annotations on an Entity class and automatically generates DTO records. You can check the DTOGen library here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parked Without further feedback this bug cannot be processed. If no feedback is provided, we close these.
Projects
None yet
Development

No branches or pull requests