@AfterMapping method not executed when project has been builded

2,042 views
Skip to first unread message

Andrea Santurbano

unread,
Oct 10, 2015, 9:46:55 AM10/10/15
to mapstruct-users
Hi guys,
i have a jHipster project where i use MapStruct, when i'm working in Eclipse everithing goes ok, but when i build the project the method annotated with @AfterMapping is not performed.
The mapper interface and the pom.xml are in attachment.

When i build the project i have to comment this dependency in order to prevent this issue https://github.com/jhipster/generator-jhipster/issues/1878:

     <dependency>
           
<groupId>org.mapstruct</groupId>
           
<artifactId>mapstruct-processor</artifactId>
           
<version>${mapstruct.version}</version>
           
<scope>provided</scope>
     
</dependency>



I think the problem is in the build process, but i can't understand where is.
Can you help me please?
Thanks
pom.xml
JmsPortalQueueMapper.java

Andrea Santurbano

unread,
Oct 10, 2015, 1:03:59 PM10/10/15
to mapstruct-users
If can help in eclipse i use m2e apt autoconfiguration which i don't know how generate the *Impl classes, instead in maven build i use the standard MapStruct configuration.

Andreas Gudian

unread,
Oct 10, 2015, 1:22:06 PM10/10/15
to Andrea Santurbano, mapstruct-users
Hi Andrea,

the pom contains the maven-processor-plugin which generates the sources to target/generated-sources with the settings mapstruct.suppressGeneratorTimestamp=true and mapstruct.defaultComponentModel=spring. The mapstruct-processor is added as plugin-dependency there. So far so good, that's one way of adding MapStruct to a project (m2e looks specifically for this plugin and then does the Eclipse annotation processor configuration based on the configuration of that plugin).

Then, you also have the artifact mapstruct-processor with scope=provided in the list of the normal dependencies of the project. By default, the compiler picks up annotation processors from the classpath automatically and calls them during the compilation - so this is the other way to add MapStruct to a project (configuration parameters to be passed to annotation processors can also be configured using the maven-compiler-plugin - but tools like m2e usually don't automatically pick up processors and their configuration when they are configured this way).

So, long story short - your Maven build generates the mappers twice: once with the maven-processor-plugin (which calls javac with -proc:only) in the generate-sources phase and once with the maven-compiler-plugin (which calls javac, and that picks up the mapstruct-processor from your classpath).

My advice would be to remove the mapstruct-processor dependency from your dependencies-section in the pom.

Cheers,
Andreas
 

--
You received this message because you are subscribed to the Google Groups "mapstruct-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapstruct-use...@googlegroups.com.
To post to this group, send email to mapstru...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrea Santurbano

unread,
Oct 10, 2015, 2:29:37 PM10/10/15
to mapstruct-users, san...@gmail.com
Hi Andreas,
thanks for the response!
I have removed the provided mapstruct-processor from my dependencies but when i build the project the *Impl classes are (again) without afterMapping methods.
When i executed the project in eclipse (again) is everything ok.
I have configured Eclipse Maven Annotation Processor with JDT ADT, and Eclipse said that outcome may differ from maven build!!! (just my case)
How can i use in mvn instal the same generation process used by eclipse!?

Andreas Gudian

unread,
Oct 10, 2015, 5:15:06 PM10/10/15
to Andrea Santurbano, mapstruct-users
Could you provide a reduced example project? I still have some trouble to grasp where exactly the differences can be that produce the different outcome.

Could you also test out what happens if you change your mapping interface and the default-methods to an abstract class? Just in case we have an issue with the handling of default methods in javac / the Eclipse compiler.

Thanks,
Andreas

Andrea Santurbano

unread,
Oct 11, 2015, 12:06:29 PM10/11/15
to mapstruct-users, san...@gmail.com
Ok if i change my mapper interface to an abstract class everything is ok!
Thanks!

Andreas Gudian

unread,
Oct 11, 2015, 1:18:29 PM10/11/15
to Andrea Santurbano, mapstruct-users
Glad to hear it works for you :).

Perhaps what you experienced then was this issue:
https://github.com/mapstruct/mapstruct/issues/636

It'll be fixed in the final version, which is the next thing that we'll release.

Cheers,
Andreas

Reply all
Reply to author
Forward
0 new messages