【问题标题】:Mapstruct mapper in src/test/java not generated by maven buildsrc/test/java 中的 Mapstruct 映射器不是由 maven build 生成的
【发布时间】:2017-03-10 08:41:42
【问题描述】:

正如标题所说,我在src/test/java中有一个mapper接口,不是mapstruct处理器生成的。

在同一个项目中,会生成src/main/java中的所有mapper。这是预期的行为吗?

如何在测试源中生成映射器?

编辑(更多信息):

简化的 Maven 模块结构:

root_project
-> module_1

root_project的pom.xml

<build>
    <pluginManagement>
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.1.0.Final</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <compilerArg>
                            -Amapstruct.defaultComponentModel=spring
                        </compilerArg>
                    </compilerArgs>
                </configuration>
            </plugin>
            ...

module_1的pom.xml基本是空的:

<dependencies>

    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-jdk8</artifactId>
        <scope>compile</scope>
    </dependency>

【问题讨论】:

  • 您是如何设置注释处理器的?你能分享你的 POM 或类似的东西吗?
  • 插件在 POM 的构建部分看起来如何? pluginManagement 中的配置看起来不错。
  • 编译是如何调用的? maven 编译器插件有compiletestCompile 阶段。如果只运行mvn compile,则只编译应用程序源代码。
  • @Filip 没有build 标签,这都是隐含的。我用clean install 构建。我刚刚重新创建了一个新项目设置,它按预期工作,所以错误必须在旧项目的配置中。如果我发现任何东西,我会更新这个问题。

标签: mapstruct


【解决方案1】:

我遇到了同样的问题并修复了它,更改了 maven 编译器插件版本。 请注意版本:Compiler 3.5.1Mapstruct 1.1.0.Final

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 2018-01-13
    • 2018-03-30
    • 2018-02-12
    • 1970-01-01
    相关资源
    最近更新 更多