首页 > 解决方案 > Mapstruct 没有为我的映射器接口之一生成实现。有没有办法知道原因?

问题描述

我正在使用 mapstruct 从/到域对象映射到 DTO 我有 20 多个正在正确生成的映射器。

我的一个映射器不再生成,但编译成功。我使用 maven 并showWarnings在配置中打开了标志maven-compiler-plugin,但是我没有看到有关该特定映射器的警告(我确实看到了其他映射器的警告)。

有没有办法从注释处理器中获取一些关于未生成的映射器的信息?

我的映射器界面(名称更改):

@Mapper
public interface PersonMapper {
    PersonMapper INSTANCE = Mappers.getMapper(PersonMapper.class);

    PersonDTO map(Person entity);

    Person map(PersonDTO dto);
}

我的 Maven 配置:

...
<dependency>
  <groupId>org.mapstruct</groupId>
  <artifactId>mapstruct-jdk8</artifactId>
  <version>1.3.0.Final</version>
</dependency>
...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
      <annotationProcessorPaths>
        ...
        <path>
          <groupId>org.mapstruct</groupId>
          <artifactId>mapstruct-processor</artifactId>
          <version>1.3.0.Final</version>
        </path>
      </annotationProcessorPaths>
      <showWarnings>true</showWarnings>
    </configuration>
  </plugin>

标签: mapstruct

解决方案


For me it was a dependency issue.

My Projet A, had a dependency to another jar B, which contained the object from my mapper method. That dependency B had a dependency C offering mapstruct mapper for many of the attribut of the object.

Somehow in my project A i was overriding explicitly the version of dependency C to an older version. So it means that some of the Obj attribute from current B version where not matching with the older C mapper. Mapstruct said nothing, just stopped generating the impl.

Not sure if this is very clear ... But check your dependencies.


推荐阅读