Could not retrieve @Mapper

2,420 views
Skip to first unread message

sheka...@gmail.com

unread,
Feb 21, 2017, 8:22:28 AM2/21/17
to mapstruct-users

Hi,

I am using mapstruct as part of my spring boot application(java 1.8) to map DTO to entities.I have been facing two issues,

issue 1 : Could not retrieve @Mapper annotation error at compilation time.

I found solution somewhere in the forum as exclude mapstruct from springfox-swagger2 dependency like below

        <dependency>
             <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <exclusions>
        <exclusion>
            <artifactId>org.mapstruct</artifactId>
            <groupId>mapstruct</groupId>
        </exclusion>
             </exclusions>
       </dependency>

what is the reason to exclude mapstruct from springfox-swagger2 and also do we have any solution other than excluding in the pom?

issue2: Mapper implementation classes could not be generated if maven-compiler-plugin is not provided.

I have plug in configuration like below in my pom file.As it is a spring boot application didn't provide version as it is managed by spring boot automatically,but if i don't provide version(3.5.1)for maven-compiler-plugin,mapper implementation classes are not getting generated.Classes are getting generated only when version 3.5.1 is provided.

             <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${java.version}</source>
  <target>${java.version}</target>
  <encoding>${project.build.sourceEncoding}</encoding>
  <annotationProcessorPaths>
  <path>
  <groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
  </path>
  </annotationProcessorPaths>
                      </configuration>
   </plugin>

Thanks,
shekar

Filip Hrisafov

unread,
Feb 21, 2017, 1:28:27 PM2/21/17
to mapstruct-users
Hi Shekar,

For issue1:

Do you have mapstruct-jdk8 in your dependencies. The exclusion from springfox is due to the fact that springfox has a compiler dependency on mapstruct and if you use mapstruct-jdk8 (that uses Java 8 Repeteable for the mappings) you have to exclude it.

For issue2:

I think that there is some bug in the versions before 3.5.1 and then the maven compiler does not pick up the annotationProcessorPaths. If you add mapstruct-processor as a provided dependency to your pom then it should work. If you do that you can accidentally use some of the internal MapStruct classes.

Andreas Gudian

unread,
Feb 21, 2017, 2:05:47 PM2/21/17
to Filip Hrisafov, mapstruct-users
Some small additions below:

Filip Hrisafov <filip.h...@gmail.com> schrieb am Di. 21. Feb. 2017 um 19:28:
Hi Shekar,

For issue1:

Do you have mapstruct-jdk8 in your dependencies. The exclusion from springfox is due to the fact that springfox has a compiler dependency on mapstruct and if you use mapstruct-jdk8 (that uses Java 8 Repeteable for the mappings) you have to exclude it.

If there were the artifacts 'mapstruct' and 'mapstruct-jdk8' with the same version on the classpath, it wouldn't be a problem. But springfox-swagger comes with an older version and that can lead to the problem (the mixture of the older mapstruct artifact and the newer mapstruct-processor trying to process your classes). In any case, the only way to get out of that is to exclude the mapstruct dependency from the springfox dep, as you are already doing it...



For issue2:

I think that there is some bug in the versions before 3.5.1 and then the maven compiler does not pick up the annotationProcessorPaths. If you add mapstruct-processor as a provided dependency to your pom then it should work. If you do that you can accidentally use some of the internal MapStruct classes.

The annotationPorcessorPaths option was added in compiler-plugin version 3.5 - with a bug regarding transitive dependencies, which won't hit you with mapstruct, and which was fixed with 3.5.1. That's why you see that version being used in our examples. The spring-boot parent pom still has an older version of the plugin configured, so you'll have to override it.



--
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.

sheka...@gmail.com

unread,
Feb 22, 2017, 1:33:53 AM2/22/17
to mapstruct-users

Thank you so much Filip.

Thanks,
shekar.

sheka...@gmail.com

unread,
Feb 22, 2017, 1:35:17 AM2/22/17
to mapstruct-users, filip.h...@gmail.com
Thank you so much Andreas.

Thanks,
Shekar.
Reply all
Reply to author
Forward
0 new messages