ichengzi / ichengzi.github.io

ichengzi's blogs and learn notes
https://ichengzi.github.io
1 stars 0 forks source link

mapStruct, lombok 混合使用问题 #46

Open ichengzi opened 3 years ago

ichengzi commented 3 years ago

https://github.com/mapstruct/mapstruct/issues/1270#issuecomment-322548757

Thanks for the nice words. We are glad that you like MapStruct 😄 .

The problem is that you have only mapstruct-processor in the annotationProcessorPaths and only that dependency is passed to the javac compiler.

The annotationProcessorPaths is there only since 3.5 so it is really strange how the mapstruct processor is invoked. In any case in order to make it work correctly you have 2 options:

  1. Add the lombok dependency to the annotationProcessorPaths as well. Then it will be picked up by the compiler and it should work.

  2. Ad the mapstruct-processor jar to your pom as a provided dependency. You will have to remove the annotationProcessorPaths in that case and the compiler will pick up the processors from your dependency. The reason why we are suggesting to use the annotationProcessorPaths is because by doing that you won't be able to use something from the mapstruct-processor module by accident. An additional reason to put it in the pom dependencies is this issue from IntelliJ (in case you are using InteliiJ 😄

You can also have a look at the mapstruct-lombok example from our repository.

I am going to close this issue as it is a problem in the configuration 😄

Originally posted by @filiphr in https://github.com/mapstruct/mapstruct/issues/1270#issuecomment-322548757

ichengzi commented 3 years ago

image

1.4.2.Final, jdk8 标记可以直接移除了, 否则maven编译时, 会报找不到 map.struct