gradle - AnnotationProcessor 和依赖项
问题描述
我正在使用 gradle / querydsl 和 JPA 2.1。
我想使用 APT(QEntities)生成 querydsl 元数据。
为此,我正在使用 gradle-apt-plugin 和 gradle 4.7
在我的项目中,我使用以下方式配置了 compileJava 选项:
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("$projectDir/src/generated2/java")
}
在我的依赖项中,我添加了
compile 'org.springframework.boot:spring-boot-starter-data-jpa'"
annotationProcessor "com.querydsl:querydsl-apt:$querydslVersion:jpa"
spring starter 将包含 javax.persistence.Entity 类的 org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final jar 添加到 compileClasspath。
启动 compileJava 任务时出现错误:
caused by: java.lang.NoClassDefFoundError: javax/persistence/Entity at com.querydsl.apt.jpa.JPAAnnotationProcessor.createConfiguration(JPAAnnotationProcessor.java:37)
不明白为什么注解处理器不能加载这个类。
解决方案
万一有人在搜索。这是我的完整解决方案(基于您的回复)。重要的部分是net.ltgt.apt*
也在 eclipse 中激活代码生成的插件,以及最后三个 querydsl 依赖项。
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins { // activates the automatic code generation
id 'net.ltgt.apt' version '0.18'
id 'net.ltgt.apt-eclipse' version '0.18'
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
runtimeOnly 'com.h2database:h2'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webflux'
// querydsl
annotationProcessor 'com.querydsl:querydsl-apt:4.1.3:jpa'
annotationProcessor 'org.springframework.boot:spring-boot-starter-data-jpa' // needed because the query dsl annotation processor doesn't recognize javax.persistence.Entity
compile 'com.querydsl:querydsl-jpa:4.1.3'
}
推荐阅读
- amazon-web-services - 如何使用新的 AWS GO SDK-V2 代入角色以进行跨账户访问
- minecraft - 如何访问我的 Minecraft 服务器控制台?
- php - PHP RSS 提要帮助获取 XML 标记以显示
- c - 我不明白这一点,而 C 中的条件
- woocommerce - 通过 Wordpress 中的文本字段内容分配用户角色
- apache-spark - 如何制作交叉验证数据集
- c - typcast 不会将整个字符串转换为 int(在 C 中)
- html - CSS 平滑文本动画
- python - 左连接字典列表
- python - 如何在kivy中制作地图屏幕,我只会黑屏