【问题标题】:how to change Mapstruct generated-sources location in multimodule maven project如何在多模块 Maven 项目中更改 Mapstruct 生成的源位置
【发布时间】:2021-07-02 20:00:43
【问题描述】:

我在 Lombok 的多模块 maven 项目中使用 mapstruct。根据官方文档设置 pom 后,mapstruct 确实正确生成了映射器实现。但是会在顶层模块中生成一个额外的文件夹。

父 pom.xml:

<plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>${java.version}</source>
          <target>${java.version}</target>
          <encoding>UTF-8</encoding>
          <compilerArgument>-Xlint:deprecation</compilerArgument>
          <showWarnings>true</showWarnings>
          <compilerArgs>
            <arg>-parameters</arg>
          </compilerArgs>
        </configuration>
      </plugin>

基于网络的 pom.xml

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <annotationProcessorPaths>
            <path>
              <groupId>org.mapstruct</groupId>
              <artifactId>mapstruct-processor</artifactId>
              <version>${org.mapstruct.version}</version>
            </path>
            <path>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok</artifactId>
              <version>1.18.16</version>
            </path>
            <!-- additional annotation processor required as of Lombok
    1.18.16 -->
            <path>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok-mapstruct-binding</artifactId>
              <version>0.2.0</version>
            </path>
          </annotationProcessorPaths>

          <showWarnings>true</showWarnings>
          <compilerArgs>
            <arg>
              -Amapstruct.suppressGeneratorTimestamp=true
            </arg>
            <arg>
              -Amapstruct.suppressGeneratorVersionInfoComment=true
            </arg>
            <arg>
              -Amapstruct.verbose=true
            </arg>
          </compilerArgs>
        </configuration>
      </plugin>

web-base 是我使用 mapstruct 的模块,而 src/main/resource... 是我不想要的生成文件夹。 如何将此位置更改为它自己的模块而不是顶部模块? 谢谢。

【问题讨论】:

    标签: spring-boot maven mapstruct


    【解决方案1】:

    MapStruct 无法控制生成源的位置。 MapStruct 是一个注解处理器,它使用 Java Annotation Processor API 来创建源代码。

    要更改位置,您需要设置 Maven 编译器插件的 generatedSourceDirectory

    【讨论】:

      猜你喜欢
      • 2018-12-11
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 2011-05-21
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多