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
Builder not available to other Annotation Processors #1538
Comments
The thing described in b867f81 is applied to all methods lombok generates. Potentially this is an ordering issue; if mapstruct runs first, that's a problem. Fortunately we solved this already, see: mapstruct/mapstruct#510 can be closed at 2018-05-18 |
@rzwitserloot I am one of the MapStruct team members. And I can guarantee you that the builder creation method, the builder class and it's methods cannot be seen during the annotation processing round. I debugged this and I can confirm that I can see the getters and setters, but not the builder. Are you creating the builder in the same time as the getters and setters? If you want I can create a sample project where you can see what happens. |
@rzwitserloot I can confirm what @filiphr had said I was trying to do a workaround and when the annotation is getting processed I can see the getters/setters but I can not see the builder method using the TypeElement for the type. |
Hi, any progress on this? In its current state I'm having to make my pojos mutable with setters so I don't have to go writing a heap of manual mapping code 👎 |
Hi, I have tested mapscruct using lombok builders when mappers and models are defined in separate modules and it works perfectly.
Is there any plan to support lombok builders when both lombok classes and mapstruct mappers are defined in the same module? |
This doesn't seem to be an issue in Lombok version 1.16.22 which is the version I get from spring boot 2.0.6. That combined with mapstruct 1.3.0.Beta2 seems to work fine with the model and the mapper in the same module. Is it possible I'm just getting lucky with the order that annotation processors are running, or is this due to changes in the newer versions of Lombok? |
I confirm, just now tested Lombok 1.18.4 and MapStruct 1.3.0.Beta2. |
@SimSonic |
@dlsrb6342 here you are: |
@SimSonic Your example is very helpful, thank you! So ... in Maven, everything is working just as you demonstrated. I'm trying the equivalent in Gradle 5.1, and not so good. I've declared in I'm new to Mapstruct. Is there some magic formula for Gradle I need to use? |
OK, I found putting Lombok first, before Am I encountering mapstruct/mapstruct#1581? |
@SimSonic have you tried to put lombok after MapStruct, like in mapstruct/mapstruct#1581? @rzwitserloot I tried with Lombok 1.18.6 and MapStruct 1.3.0.Final. With gradle and maven when Lombok is first we can only see the getters and setters, but not the builder method. If Lombok is second it is fine. Have a look at https://github.com/filiphr/mapstruct-examples/tree/lombok-ordering/mapstruct-lombok. That is one of our Lombok examples and when you try to compile with Maven or Gradle it won't work and it will give the error:
If you switch the order it will compile properly. You can put a break point in |
Hi, |
Don't know if it is relevant but if I put lombok after mapstruct I lose warnings/errors about not mapped properties when property is in subclass:
In the end I have to remove I used
|
Putting lombok after mapstruct also worked for me As per the mapstruct lombok example https://github.com/filiphr/mapstruct-examples/tree/lombok-ordering/mapstruct-lombok/src/main/java/com/mycompany I use |
+1 for fixing this. We run into this issue when we try to use annotation processing of |
+1 for fixing this After updating Spring Boot from 2.3.4.RELEASE to 2.4.0 (with lombok upgraded automatically from 1.18.12 to 1.18.16) this issue occured and MapStruct couldn't see the generated builder classes. |
@dnaumovich the upgrade from 1.18.12 to 1.18.16 has nothing to do with this issue, but rather with the breaking change mentioned in the Lombok release notes. You need to add |
putting lombock before mapstruct work for me in annotationProcessorPaths section when defining plugin. |
@filiphr assumption is right and lombok has to create symbols/mirrors for the new methods and types. It works if you run lombok after mapstruct because mapstruct postpones mapper creation to a later round if it detects lombok. In a new annotation processing round javac recreates the type mirrors and the builder can be found by other annotation processors. While working on this issue I noticed that the current soloution is somehow incomplete because it does not add type parameters to the method. It also seems to be a lot of work to always copy the type information by hand and it can get really tricky to do it right in more complex cases ( |
This comment has been minimized.
This comment has been minimized.
Hello folks who type '+1 for fixing this': Stop doing that. There's a thumbs up thing you can use. |
Probably not. It's been so long, it's possible I tried that concluded it didn't work, but if memory serves, I just wrote the copy code because I thought 'eh, how hard could it be?' (and then generics says 'hi!' and I facepalm). Netbeans is more generally problematic; I think it's acceptable if it's at the cost of netbeans, though I would then like to put something on the docket to at least meet netbeans halfway. Hopefully to just fix things so they work with netbeans, potentially that we resort to the old copying code if netbeans is detected. One major issue there is that I don't currently have an easy setup to run lombok+netbeans together and e.g. add some breakpoints to see what's going on. |
I added
Disabling the whole copy code seems to work too, at least there are no errors and I also successfully run mapstruct after lombok in netbeans. |
@filiphr I am very puzzled. In the compatibility scheme of lombok and mapstructs provided at the following URL https://mapstruct.org/documentation/stable/reference/html/#lombok |
I don't know what to tell you @kaipengliu. We have tests for this and it works correctly. This issue was closed on 18th of April 2021, the last release of Lombok is from 2nd of April 2021. Therefore, you can have problems with any of the current versions. You need to wait for the Lombok team to do a new release or try the Lombok Edge version |
…ombok's builder in mapstruct generated code * See https://stackoverflow.com/questions/65955000/how-to-instruct-mapstruct-to-use-lombok-builder#65955495 * See projectlombok/lombok#1538 (comment)
I've been playing around with adding support for Builder in MapStruct and I have noticed that the public static method with no arguments created by Lombok and the Builder itself is not available during the annotation processing phase.
I don't know the code that much. However, I suppose that it needs something similar to what was done for getters and setter in b867f81.
Would it be possible to have the builder creation method, the Builder and the builder method types to be available to other annotation processors?
The text was updated successfully, but these errors were encountered: