1

I'm working on a java 8 gradle project in Eclipse (2019-09) including lombok. I would love to use mapstruct for converting models into dto and vice versa. Mapstruct works great.

Problem: I have some trouble that Eclipse creates and compiles the mapper implementation when saving the file. The XYMapperImpl.java/class files are only created when using ./gradlew classes. Building it with gradle is not really an option because it takes some time and does not really work in my workflow. I need to have the .class file at the end to mount the whole /bin folder into a docker container.

I'm using the Eclipse MapStruct plugin, however this is only for Code Completion and Quick Fixes but not for generating class files.

I've done some research: How to get Eclipse to generate MapStruct Mappers using Gradle or How to properly integrate MapStruct with Eclipse? (Including Lombok java agent) and some others without any success.

Maybe I missed something?

My build.gradle file:

plugins {
id 'java'
id "net.ltgt.apt-eclipse" version "0.21"
id "net.ltgt.apt" version "0.21"
}

apply plugin: "java"
apply plugin: "net.ltgt.apt-eclipse"
apply plugin: "net.ltgt.apt"

repositories {
    mavenCentral()
}

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.10'
    compile "org.mapstruct:mapstruct-jdk8:1.3.0.Final"

    annotationProcessor "org.mapstruct:mapstruct-processor:1.3.0.Final" //Must be defined before the     lombok annotationProcessor
    annotationProcessor 'org.projectlombok:lombok:1.18.6'
}

I've created a simple demo project as an example.

wprogLK
  • 488
  • 5
  • 11
  • If you want to execute something, e.g. generate code, when a changed project file is saved, you can use an [Ant script as project builder](https://help.eclipse.org/2019-12/topic/org.eclipse.platform.doc.user/gettingStarted/qs-93_project_builder.htm). – howlger Jan 13 '20 at 16:08
  • @howlger: Thanks for your suggestion. However, accordingly to this post (https://stackoverflow.com/questions/45518161/how-to-get-eclipse-to-generate-mapstruct-mappers-using-gradle) it should work without any ANT, just with gradle (for config source) and Eclipse – wprogLK Jan 14 '20 at 08:50
  • Great. Do you want to give a self-answer or should the question be closed as a duplicate? – howlger Jan 14 '20 at 08:52
  • My problem is that it's not working as expected accordingly to the other post. – wprogLK Jan 14 '20 at 10:37
  • Then go for a self-answer to help others with the same problem. – howlger Jan 14 '20 at 11:58
  • @howlger: I'm sure he will do that IF he gets it to work, which is clearly not the case, yet, right? I was investigating the same and also got the impression that it should work, but then it doesn't :( – marc82ch Jan 17 '20 at 14:59

0 Answers0