将 Mapstruct 与 Kotlin 一起用于生成源时出现 NonExistentClass 错误

NonExistentClass error when using Mapstruct with Kotlin for generated sources

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

当我编译项目时,Mapstruct 似乎无法找到 OpenApi3 codegen 插件生成的源代码,因为生成的实现包含 NonExistentClass 而不是我的 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>

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

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

编辑: 可以在此处找到重现此内容的简单示例:https://github.com/tobisinghania/kotlin-openapi3-mapstruct-failure

问题是由于kotlin maven插件配置中缺少<sourceDir>target/generated-sources/openapi/src/main/java</sourceDir>

我在你的回购协议上做了一个 Pull Request