将 Mapstruct 与 Kotlin 结合使用生成源时出现 NonExistentClass 错误

Tob*_*obi 7 annotation-processing kotlin mapstruct openapi

我想使用 Mapstruct 将内部模型映射到 Kotlin 项目中由 OpenApi3 codegen 生成的模型。

当我编译项目时,Mapstruct 似乎无法找到 OpenApi3 codegen 插件生成的源,因为生成的实现包含 aNonExistentClass而不是我的 OpenApi 模型。

我的插件配置是

<plugin>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-maven-plugin</artifactId>
    <configuration>
        <args>
            <arg>-Xjsr305=strict</arg>
        </args>
        <compilerPlugins>
            <plugin>spring</plugin>
            <plugin>jpa</plugin>
        </compilerPlugins>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-allopen</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-noarg</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
    </dependencies>

    <executions>
        <execution>
            <id>kapt</id>
            <phase>process-sources</phase>
            <goals>
                <goal>kapt</goal>
            </goals>
            <configuration>
                <sourceDirs>
                    <sourceDir>src/main/kotlin</sourceDir>
                    <sourceDir>src/main/java</sourceDir>
                </sourceDirs>
                <annotationProcessorPaths>
                    <annotationProcessorPath>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                    </annotationProcessorPath>
                </annotationProcessorPaths>
            </configuration>
        </execution>

        <execution>
            <id>compile</id>
            <phase>process-sources</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
        <execution>
            <id>test-compile</id>
            <phase>process-test-sources</phase>
            <goals>
                <goal>test-compile</goal>
            </goals>
        </execution>

    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

看来问题与kapt查找生成的 Java 源有关。

我的配置是否损坏或者我遇到了 kotlin 注释处理器的限制?

编辑:可以在这里找到重现此问题的简单示例:https ://github.com/tobisinghania/kotlin-openapi3-mapstruct-failure

Lau*_*tre 5

<sourceDir>target/generated-sources/openapi/src/main/java</sourceDir>该问题是由于kotlin maven 插件配置缺失造成的

我已经对你的仓库 提出了Pull 请求,