【发布时间】:2021-12-29 02:54:21
【问题描述】:
我正在按照这个示例https://felixzett.com/articles/minimal-maven-kotlin-querydsl-example/ 在 Springboot Kotlin Maven 项目中实现 querydsl。使用提到的pom,我在运行mvn compile后设法生成q类,并且也可以成功运行mvn clean install,但是当我尝试在本地运行项目时,我在所有q类中都出现错误。
java: cannot find symbol
symbol: class Generated
location: package javax.annotation.processing
我尝试将 javax.annotation-api 添加到 <annotationProcessPaths> 元素,但没有成功。
<annotationProcessorPath>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</annotationProcessorPath>
我还尝试将它作为依赖项添加到该 <plugin> 元素或主 <dependencies> 元素中,但这些都不起作用。
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
请问有人知道如何解决这个问题吗?
更新:
我的 pom.xml 中有 kotlin-maven-plugin 和 maven-compiler-plugin。我意识到如果我注释掉 maven-compiler-plugin 那么错误就消失了。但是我不确定如果没有这个插件,应用的其他部分是否会受到影响。
有谁知道只有 kotlin-maven-plugin 是否可以,或者我应该如何修改 maven-compiler-plugin 以使 2 个插件协同工作?
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>kapt</id>
<phase>generate-sources</phase>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<classifier>jpa</classifier>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/test/kotlin</sourceDir>
<sourceDir>target/generated-sources/kapt/test</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
<plugin>jpa</plugin>
<plugin>all-open</plugin>
</compilerPlugins>
<pluginOptions>
<option>all-open:annotation=javax.persistence.Entity</option>
<option>all-open:annotation=javax.persistence.MappedSuperclass</option>
<option>all-open:annotation=javax.persistence.Embeddable</option>
</pluginOptions>
<jvmTarget>1.8</jvmTarget>
</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>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
【问题讨论】:
-
对于 Java 8+,我们鼓励您使用 Querydsl 5.0.0。
-
@Jan-WillemGmeligMeyling 我尝试使用 querydsl 5.0.0 但仍然有同样的错误。我更新了我的问题,你能帮忙看看吗?谢谢!
标签: spring-boot maven kotlin querydsl