11

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:

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

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>

Expected result would be:

  • 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

Important edit: I'm also using the lombok javaagent

Andrea Saba
  • 331
  • 1
  • 3
  • 6
  • Other test with "eclipse-jee-2018-12-R-win32-x86_64" also failed – Andrea Saba Apr 08 '19 at 16:49
  • Other test with "java-se-8u40-ri" (with both mapstruct-jdk8 and mapstruct dependencies) also faied – Andrea Saba Apr 08 '19 at 16:52
  • Update: I looked at the logs in eclipse and this is what I have java.lang.NoClassDefFoundError: org/mapstruct/ap/spi/AstModifyingAnnotationProcessor – Andrea Saba Apr 09 '19 at 07:18
  • Another hint, I'm also availing of the lombok eclipse java agent which looks to be an issue per se (https://github.com/mapstruct/mapstruct/issues/1159) – Andrea Saba Apr 09 '19 at 08:43

2 Answers2

4

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)

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:

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

Andrea Saba
  • 331
  • 1
  • 3
  • 6
  • Mmm...it seems it doesn't work with lombok 1.18.12. I tried removing that class from the package but the error is still there. Also, if I just use 1.16.12 I don't need to remove that class at al – Phate Mar 31 '20 at 13:31
1

I actually faced a very similar issue and solved it in a slightly different manner.

  1. As descibed by OP make sure this property is declared in the pom.xml:

    <properties> ... <m2e.apt.activation>jdt_apt</m2e.apt.activation> ... </properties>

  2. Obviously the m2e-apt plugin for eclipse must be installed: https://marketplace.eclipse.org/content/m2e-apt

  3. In the pom.xml make sure that mapstruct-processor and lombok are in scope provided.

  4. Last but not least: I had to tweak the lombok.jar by adding the org.mapstruct.ap.spi.AstModifyingAnnotationProcessor.class file to the jar (see https://github.com/mapstruct/mapstruct/issues/1159#issuecomment-328974483).

Tested with Eclipse 2019-03, Lombok 1.18.6 and Mapstruct 1.2.0.Final.

Hope this helps!

Chris L
  • 11
  • 1
  • Chris, it's ok if it works, anyway I wouldn't generally feel more comfortable by removing a class file from a jar. – Andrea Saba Apr 21 '19 at 10:53