Kotlin-Kapt Annotation Processor not working with

2019-07-29 15:07发布

问题:

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

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.

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>

回答1:

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>

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.