本文介绍了Kotlin-Kapt注释处理器无法与Maven一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从kotlin实体类生成jpa querydsl文件.

I want to generate jpa querydsl files from kotlin entity classes.

在线上有一个非常好的示例,说明如何使用gradle https://github.com/JetBrains/kotlin-examples/blob/master/gradle/kotlin-querydsl/build.gradle .

There is a very good examples online of how to generate the dsl files using gradle https://github.com/JetBrains/kotlin-examples/blob/master/gradle/kotlin-querydsl/build.gradle.

但是我试图在Maven中实现它,但是没有运气.我当前的pom在下面.有人知道这个问题可能是什么吗?提前致谢.

However I have tried to implement this in maven and have had no luck.My current pom is below. Does anybody know what the issue might be?Thanks in advance.

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>test</groupId>
<artifactId>test-jpa</artifactId>
<version>2.7.0-SNAPSHOT</version>

<properties>
    <kotlin.version>1.1.50</kotlin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.5.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jre8</artifactId>
        <version>${kotlin.version}</version>
    </dependency>

</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>kotlin-maven-plugin</artifactId>
            <groupId>org.jetbrains.kotlin</groupId>
            <version>${kotlin.version}</version>

            <executions>
                <execution>
                    <id>kapt</id>
                    <goals>
                        <goal>kapt</goal>
                    </goals>
                    <configuration>
                        <sourceDirs>
                            <sourceDir>${project.basedir}/src/main/java</sourceDir>
                        </sourceDirs>
                        <annotationProcessorPaths>
                            <annotationProcessorPath>
                                <groupId>com.mysema.querydsl</groupId>
                                <artifactId>querydsl-apt</artifactId>
                                <version>3.6.4</version>
                            </annotationProcessorPath>
                        </annotationProcessorPaths>
                    </configuration>
                </execution>

                <execution>
                    <id>compile</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                    <configuration>
                        <sourceDirs>
                            <sourceDir>src/main/java</sourceDir>
                            <sourceDir>${project.build.sourceDirectory}</sourceDir>
                        </sourceDirs>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>

</build>

推荐答案

潜在的问题是您错过了jpa分类器:

The potential problem is that you missed the jpa classifier:

<annotationProcessorPath>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-apt</artifactId>
    <version>3.6.3</version>
    <classifier>jpa</classifier>
</annotationProcessorPath>

我添加了 Maven/Querydsl示例 kotlin-examples 存储库.请注意,该示例的pom稍微复杂些,因为它还支持Java/Kotlin组合项目.

I added a Maven/Querydsl example to the kotlin-examples repository. Note that the example has a slightly more complicated pom as it also supports Java/Kotlin combined projects.

这篇关于Kotlin-Kapt注释处理器无法与Maven一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 20:14