如何将MapStruct与Eclipse正确集成? (包括Lombok Java代理) [英] How to properly integrate MapStruct with Eclipse? (Including Lombok java agent)

查看:2607
本文介绍了如何将MapStruct与Eclipse正确集成? (包括Lombok Java代理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意在某些官方项目中使用MapStruct,所以我决定先对其进行一些测试;我需要使其与eclipse集成在一起,并遵循MapStruct网站上提供的所有说明,但是...到目前为止还算不上什么. 有人成功进行了这种整合吗??如果是,我会缺少什么?

I'm willing to use MapStruct in some official project so I decided to give it some testing first; I'd need to make it work integrated with eclipse and followed all the instructions provided on MapStruct website but ... so far no luck. Did anyone succeeded on such integration? and if yes what can I be missing?

我的测试从一个更大的东西开始,但是当我意识到它不起作用时,我决定使用一个较小的示例,所以我做了这件事:

My test started with something bigger, but when I realized it was not working I decided to use a smaller example, so this is what I did:

  • Using openjdk-10.0.1_windows-x64
  • downloaded and installed a fresh version of eclipse (eclipse-jee-2019-03-R-win32-x86_64)
  • installed latest m2e-apt (and mapstruct plugin though not needed for this exercise) as suggested in http://mapstruct.org/documentation/ide-support/
  • downloaded https://github.com/mapstruct/mapstruct-examples
  • imported from git (from within eclipse) mapstruct-clone project (looked the basic-est example)
  • checked the settings as suggested in http://mapstruct.org/documentation/dev/reference/html/ (chap 2.1) and everything looks good

...无法说服Eclipse自动生成mapper实现,我什至在pom中添加了jdt_apt行.

... no way to persuade eclipse to auto-generate the mapper implementation, I even added the jdt_apt line to the pom.

这是pom.xml的一小段-有关完整代码,请参阅mapstruct-clone项目.

Here is a snippet of the pom.xml - please refer to he mapstruct-clone project for the whole code.

<properties>
    <org.mapstruct.version>1.3.0.Final</org.mapstruct.version>
    <m2e.apt.activation>jdt_apt</m2e.apt.activation>
</properties>

预期结果将是:

  • 在下面找到我重新生成的类 保存映射时出现目标/生成的源/注释" 界面
  • (如 http://mapstruct.org/documentation/dev/reference/html/ ",它将设置MapStruct注释处理器,使其正确运行 在IDE中,无论何时保存映射器类型.整洁,不是吗?)
  • 但不要
  • 我只能通过"MVN全新安装"生成类 很好但是不是那么方便
  • to find my re-generated classes under "target/generated-sources/annotations" when I save a mapping interface
  • (as stated by http://mapstruct.org/documentation/dev/reference/html/ " it will set up the MapStruct annotation processor so it runs right in the IDE, whenever you save a mapper type. Neat, isn’t it?")
  • but do not
  • I can only get the classes generated through a "mvn clean install" which is good but not that handy

重要我也在使用lombok javaagent

推荐答案

我最终找到了解决该问题的方法(= D)

I eventually found the solution to the issue ( =D )

  • first thanks to Sjaak Derksen from MapStruct team for supporting me
  • second thanks to Pavel Horal for posting this solution https://github.com/mapstruct/mapstruct/issues/1159
  • and finally thanks to myself for being so stubborn (well sometimes it helps)

该问题确实与Lombok Java代理和MapStruct之间的不兼容有关. 要使其正常工作,请按照Pavel在上一篇文章中的建议进行操作,它将起作用:

The issue was indeed tied to an incompatibility between Lombok java agent and MapStruct. To get it to work just do what Pavel suggested in his last post and it will work:

[...]只需删除lombok.jar中的SPI注册(通过删除META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor)[...]

[...] simply remove the SPI registration inside lombok.jar (by deleting META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor) [...]

这篇关于如何将MapStruct与Eclipse正确集成? (包括Lombok Java代理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆