7

Is there any special copnfiguration to get eclipse to generate the Mapstruct mappers? Curently they are not being generated.

They do generate in a gradle build but I cannot get them to generate so I can use them in development.

I added this to my build.gradle:

plugins {
    id "net.ltgt.apt" version "0.10"
}
dependencies {
    compile "org.mapstruct:mapstruct-jdk8:$mapstructVersion"
    apt "org.mapstruct:mapstruct-processor:$mapstructVersion"
}

I also added the eclipse plugin for MapStruct (although I belive that this is not actually required???)

I then went Project > Properties > Java Compiler > Annotation Processing:

screenshot

But .apt_generated is empty, what am I missing?

I'm using:

Eclipse: Version: Oxygen Release (4.7.0) Build id: 20170620-1800

MapStruct version 1.2.0.CR1 (also tries 1.1.0.FINAL)

Neilos
  • 2,696
  • 4
  • 25
  • 51

1 Answers1

12

So after a bit of searching I determined that the solution is that you have to manually run the eclipse task in gradle. You should then see similar to the following if it is successful:

enter image description here

The solution came from reading https://github.com/tbroyer/gradle-apt-plugin docs which states:

When using Buildship, you'll have to manually run the eclipseJdtApt and eclipseFactorypath tasks to generate the Eclipse configuration files, then either run the eclipseJdt task or manually enable annotation processing: in the project properties → Java Compiler → Annotation Processing, check Enable Annotation Processing. Note that while all those tasks are depended on by the eclipse task, that one is incompatible with Buildship, so you have to explicitly run the two or three aforementioned tasks and not run the eclipse task.

It states that the eclipse task is incompatible with buildship but that seems to be fixed (I ran the eclipse task and had no issues):

enter image description here

I did however have issues with the cleanEclipse task which does seem to be incompatible with Buildship.

After all this the *MapperImpl.java classes are generated in <project_root>/.apt_generated

Neilos
  • 2,696
  • 4
  • 25
  • 51
  • 1
    Great that you managed to figure out the solution to your problem. I also created an [issue](https://github.com/mapstruct/mapstruct.org/issues/63) for our website, so we can integrate your answer in the [IDE Support](http://mapstruct.org/documentation/ide-support/) part of the website. – Filip Aug 06 '17 at 19:54
  • If you also use Lombok you might be up a creek without a paddle. – Justin Sep 29 '17 at 13:12
  • 1
    @Justin There seems to presently be an issue with using both Lombok `1.16.18` and Mapstruct `1.2.0.Final` in Eclipse (AFAIK it works in other IDEs, and certainly works in Gradle) see https://github.com/mapstruct/mapstruct/issues/1159 and https://github.com/rzwitserloot/lombok/issues/1359 the workaround of adding `org.mapstruct.ap.spi.AstModifyingAnnotationProcessor.class` file to the `lombok.jar` works for me, hopefully it will be fixed soon. – Neilos Oct 27 '17 at 09:16
  • @Neilos Luckily I'm using Gradle so that's basically been my work-a-around. I tried adding that class to the JAR but IIRC either the package structure in the JAR was different or I just got confused with what I was supposed to do. I'm using the latest Eclipse Oxygen and its not fixed there yet. I share your hope! :-D – Justin Oct 28 '17 at 19:56
  • 1
    @Justin here is the modified JAR, after installing lombok in eclipse replace the lombok.jar with this one https://1drv.ms/u/s!AucAWW_UyaMUhVOvKLNC5twrDVDh – Neilos Oct 30 '17 at 12:30
  • @Neilos thanks! I'll check it out to see how the fix is supposed to work :-) – Justin Oct 31 '17 at 13:27
  • @Justin after installing Lombok in eclipse (https://projectlombok.org/setup/eclipse) you'll notice a `lombok.jar` in your eclipse installation directory, that's the one you need to replace. – Neilos Oct 31 '17 at 14:15
  • After I imported my project, I have my annotation processors section looking very similar to yours. But, Eclipse generates nothing gets generated under `.apt_generated`. Here is a sample project I created, which I imported into `STS` using `Buildship` https://github.com/thekalinga/gradle-apt-plugin-eclipse-issue Any idea why eclipse is not generating anything? – Ashok Koyi Apr 17 '18 at 22:05
  • I ran `./gradlew eclipseJdtApt eclipseFactorypath` and refresh project inside eclipse to see the annotation processor changes you have presented here – Ashok Koyi Apr 17 '18 at 22:18
  • Have raised an issue https://github.com/tbroyer/gradle-apt-plugin/issues/79 Not sure for a fact that the issue is with the plugin/IDE – Ashok Koyi Apr 17 '18 at 23:00
  • @AshokKoyi it's all a bit troublesome presently, the easiest work around is to revert to MapStruct v1.1.0.Final for now until they fix it. Or use another IDE. – Neilos Nov 03 '18 at 04:28