[英]QueryDSL Q Classes Not Generating after Java 17 Upgrade
提示:本站为国内最大中英文翻译问答网站,提供中英文对照查看,鼠标放在中文字句上可显示英文原文。
我正在升级一个使用 Spring Boot 2.7.5 和 QueryDSL 5.0 的 Gradle 7.5 项目,从 Java 8 升级到 Java 17。该项目在升级之前工作,但之后,它没有构建,因为最终的 CompileJava 执行记录了一个“找不到代码中所有 Q class 引用的符号”错误。
我认为这些类要么以不同方式存储,要么没有生成。
此外,如果这有帮助,我将 VS Code 用作我的 IDE,但我正在从标准 Windows 命令提示符运行我的所有 Gradle 命令。
我查看了 Stack Overflow 和其他站点以了解与此相关的问题。 不幸的是,虽然这个问题已经在不同的背景下被问到,但他们的答案并不适合我的背景。 以下是我查看的一些地方,以防这对其他人有帮助:
这是我的 build.gradle。请注意,当我有“sourceCompatability = 1.8”并且还没有开始使用工具链符号甚至 Java 17 时,它正在工作。还知道我没有从头开始创建这个文件,但正在编辑一个那是别人开始的。
此外,失败的是“bootRun”任务中的“compileJava”命令(“运行”应用程序的主要任务是“MyAppRun”。它依次执行“preCompile”、“generateJPA”、“generateQueryDSL”和“bootRun”的顺序)。 我预计“generateQueryDSL”任务需要有所改变。
我是 Gradle 和 QueryDSL 的新手,非常感谢任何建议。
提前致谢!
plugins {
id 'org.springframework.boot' version '2.7.5'
// id 'net.ltgt.apt' version '0.18'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.mydomain'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
// sourceCompatibility = '17.0.6'
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
}
configurations {
hibernatetool
querydslapt
}
configurations.implementation.canBeResolved = true
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
}
generated {
java {
srcDir "$projectDir/generated/java"
}
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-jersey'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-config:5.6.8'
implementation 'org.springframework.security:spring-security-core:5.6.8'
implementation 'org.springframework.security:spring-security-oauth2-resource-server:5.6.8'
implementation 'org.springframework.security:spring-security-oauth2-jose:5.6.8'
runtimeOnly group: 'com.nimbusds', name: 'oauth2-oidc-sdk', version: '6.23'
implementation 'org.hibernate:hibernate-core:5.6.12.Final'
implementation 'org.hibernate:hibernate-tools:5.6.2.Final'
implementation 'org.springframework.data:spring-data-rest-hal-explorer'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
implementation group: 'org.json', name: 'json', version: '20200518'
runtimeOnly 'org.postgresql:postgresql'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
exclude group: 'junit', module: 'junit'
}
hibernatetool group:'org.hibernate', name:'hibernate-core', version:'5.6.12.Final'
hibernatetool group:'org.hibernate', name:'hibernate-tools', version:'5.6.2.Final'
hibernatetool group:'org.hibernate', name:'hibernate-entitymanager', version:'5.6.12.Final'
hibernatetool group:'org.postgresql', name:'postgresql'
implementation("com.querydsl:querydsl-core:5.0.0")
implementation("com.querydsl:querydsl-jpa:5.0.0")
implementation('com.google.guava:guava:31.1-jre')
implementation('com.google.code.findbugs:jsr305:3.0.2')
annotationProcessor("com.querydsl:querydsl-apt:5.0.0:jpa")
annotationProcessor('org.springframework.boot:spring-boot-starter-data-jpa')
annotationProcessor('org.springframework.boot:spring-boot-starter-data-rest')
annotationProcessor('javax.persistence:javax.persistence-api:2.2')
annotationProcessor('javax.annotation:javax.annotation-api:1.3.2')
implementation fileTree(include: ['*.jar'], dir: './libs')
/* annotationProcessor 'com.querydsl:querydsl-apt:4.2.1: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.2.1'*/
}
springBoot {
if (project.hasProperty('import')) {
mainClass = 'com.mydomain.MyAppservices.ImportApplication'
} else {
mainClass = 'com.mydomain.MyAppservices.MyAppApplication'
}
}
bootRun {
if (project.hasProperty('import')) {
args project.import
}
compileJava {
options.compilerArgs << "-proc:none"
}
}
task preCompile (type: JavaCompile) {
source = sourceSets.main.java.srcDirs
include 'com/mydomain/MyAppservices/config/MyAppReverseEngineeringStrategy.java'
classpath = configurations.implementation
destinationDirectory = file("build/classes/java/main")
}
task generateJPA {
group 'MyApp'
description 'Generate JPA Entities'
doLast{
delete 'src/main/java/com/mydomain/MyAppservices/model', '*'
delete fileTree('src/main/java/com/mydomain/MyAppservices/views') { include 'Q*' }
ant {
taskdef(name: 'hibernateTool',
classname: 'org.hibernate.tool.ant.HibernateToolTask',
classpath: configurations.hibernatetool.asPath)
hibernateTool {
jdbcconfiguration(propertyFile: 'resources/hibernate.reveng.properties',
detectmanytomany: 'true',
reversestrategy: 'com.mydomain.MyAppservices.config.MyAppReverseEngineeringStrategy',
packagename: 'com.mydomain.MyAppservices.model',
revengfile: 'resources/hibernate.reveng.xml')
hbm2java(destdir: 'src/main/java', ejb3: 'true', jdk5: 'true')
classpath {
pathElement(path: "build/classes/java/main")
}
}
}
}
}
task generateQueryDSL (type: JavaCompile) {
group 'MyApp'
description "Generate QueryDSL classes"
options.compilerArgs << "-s"
options.compilerArgs << "src/main/java/"
options.compilerArgs << "-proc:only"
options.compilerArgs << '-processor'
options.compilerArgs << 'com.querydsl.apt.jpa.JPAAnnotationProcessor'
options.annotationProcessorPath = configurations.annotationProcessor
source = sourceSets.main.java.srcDirs
classpath = configurations.implementation + configurations.annotationProcessor
destinationDirectory = file("build/classes/java/main")
}
generateJPA.dependsOn preCompile
generateQueryDSL.dependsOn generateJPA
task generate {
group 'MyApp'
description "Generate all JPAs and QueryDSL classes"
dependsOn generateQueryDSL
}
task MyAppRun {
dependsOn bootRun
dependsOn generate
tasks.findByName('bootRun').mustRunAfter 'generate'
}
task cleanGenerated {
doLast{
delete 'src/main/java/com/mydomain/MyAppservices/model', '*'
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.