gradle 的 QueryDSL 问题
我将 QueryDSL 与 Lombok 和 gradle 一起使用。 Q 类正在生成,IDEA 也可以看到它们,并且没有编译器错误,但是当我尝试执行 gradle build 时,我得到:
error: cannot find symbol
import QRole;
所以文件已生成,但 gradle build 无法看到它们。我发现的所有解决方案都不起作用,无论我做什么,我仍然收到此错误。这是我的 gradle.build :
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'checkstyle'
id 'org.sonarqube' version '3.3'
id 'jacoco'
id 'idea'
id 'com.github.ben-manes.versions' version '0.42.0'
}
dependencies {
// Annotation processors
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
// Mapstruct
implementation group: 'org.mapstruct', name: 'mapstruct', version: mapstructVersion
annotationProcessor group: 'org.mapstruct', name: 'mapstruct-processor', version: mapstructVersion
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: javaxAnnotationVersion
annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.2-api', version: jpaVersion
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.2-api', version: jpaVersion
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-sql', version: querydslVersion
// Spring boot
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.springframework.retry', name: 'spring-retry', version: springRetry
// Promotheus Monitoring (exposes /actuator/promotheus)
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
// Persistence
runtimeOnly group: 'org.postgresql', name: 'postgresql', version: postgresVersion
implementation group: 'org.flywaydb', name: 'flyway-core', version: flywayVersion
implementation group: 'org.hibernate', name: 'hibernate-jcache', version: hibernateVersion
implementation(group: 'org.hibernate', name: 'hibernate-spatial', version: hibernateVersion) {
exclude group: 'org.postgresql', module: 'postgresql'
}
implementation group: 'com.vladmihalcea', name: 'hibernate-types-52', version: hibernateTypesVersion
// Apache commons
implementation group: 'org.apache.commons', name: 'commons-lang3', version: apacheCommonsLangVersion
implementation group: 'org.apache.commons', name: 'commons-collections4', version: apacheCommonsCollectionVersion
// Swagger
implementation group: 'io.springfox', name: 'springfox-swagger2', version: swaggerVersion
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: swaggerVersion
// Jackson Datatype Jts
implementation group: 'com.bedatadriven', name: 'jackson-datatype-jts', version: jacksonDatatypeJTSVersion
// JWT
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: jjwtVersion
// Logging dependencies
runtimeOnly group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: logstashVersion
// Tests
testImplementation(group: 'org.springframework.boot', name: 'spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
// Mockito
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoVersion
//JUnit
testImplementation group: 'junit', name: 'junit', version: junitVersion
//CSV
implementation group: 'org.apache.commons', name: 'commons-csv', version: apacheCommonsCsvVersion
// S3
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: awsSdkVersion
// SES
implementation group: 'com.amazonaws', name: 'aws-java-sdk-ses', version: awsSdkVersion
// AWS Secrets Manager
implementation group: 'com.amazonaws', name: 'aws-java-sdk-secretsmanager', version: awsSdkVersion
// RDS IAM access control
implementation group: 'io.magj', name: 'iam-jdbc-driver', version: '0.1.8'
// Scheduling
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-spring', version: shedLockVersion
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-provider-jdbc-template', version: shedLockVersion
}
dependencies {
compileOnly "com.querydsl:querydsl-jpa:${querydslVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor(
"com.querydsl:querydsl-apt:${querydslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:${hibernateJPAVersion}",
"javax.annotation:javax.annotation-api:${javaxAnnotationVersion}",
"org.projectlombok:lombok"
)
}
I am using QueryDSL with Lombok and gradle. Q classes are getting generated, also IDEA can see them and there is no compiler error but when i try to execute gradle build i get :
error: cannot find symbol
import QRole;
So files are generated but gradle build like can't see them. All of solutions i found are not working and what ever i do i still get this error. Here is my gradle.build :
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'checkstyle'
id 'org.sonarqube' version '3.3'
id 'jacoco'
id 'idea'
id 'com.github.ben-manes.versions' version '0.42.0'
}
dependencies {
// Annotation processors
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
// Mapstruct
implementation group: 'org.mapstruct', name: 'mapstruct', version: mapstructVersion
annotationProcessor group: 'org.mapstruct', name: 'mapstruct-processor', version: mapstructVersion
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: javaxAnnotationVersion
annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.2-api', version: jpaVersion
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.2-api', version: jpaVersion
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-sql', version: querydslVersion
// Spring boot
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.springframework.retry', name: 'spring-retry', version: springRetry
// Promotheus Monitoring (exposes /actuator/promotheus)
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
// Persistence
runtimeOnly group: 'org.postgresql', name: 'postgresql', version: postgresVersion
implementation group: 'org.flywaydb', name: 'flyway-core', version: flywayVersion
implementation group: 'org.hibernate', name: 'hibernate-jcache', version: hibernateVersion
implementation(group: 'org.hibernate', name: 'hibernate-spatial', version: hibernateVersion) {
exclude group: 'org.postgresql', module: 'postgresql'
}
implementation group: 'com.vladmihalcea', name: 'hibernate-types-52', version: hibernateTypesVersion
// Apache commons
implementation group: 'org.apache.commons', name: 'commons-lang3', version: apacheCommonsLangVersion
implementation group: 'org.apache.commons', name: 'commons-collections4', version: apacheCommonsCollectionVersion
// Swagger
implementation group: 'io.springfox', name: 'springfox-swagger2', version: swaggerVersion
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: swaggerVersion
// Jackson Datatype Jts
implementation group: 'com.bedatadriven', name: 'jackson-datatype-jts', version: jacksonDatatypeJTSVersion
// JWT
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: jjwtVersion
// Logging dependencies
runtimeOnly group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: logstashVersion
// Tests
testImplementation(group: 'org.springframework.boot', name: 'spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
// Mockito
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoVersion
//JUnit
testImplementation group: 'junit', name: 'junit', version: junitVersion
//CSV
implementation group: 'org.apache.commons', name: 'commons-csv', version: apacheCommonsCsvVersion
// S3
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: awsSdkVersion
// SES
implementation group: 'com.amazonaws', name: 'aws-java-sdk-ses', version: awsSdkVersion
// AWS Secrets Manager
implementation group: 'com.amazonaws', name: 'aws-java-sdk-secretsmanager', version: awsSdkVersion
// RDS IAM access control
implementation group: 'io.magj', name: 'iam-jdbc-driver', version: '0.1.8'
// Scheduling
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-spring', version: shedLockVersion
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-provider-jdbc-template', version: shedLockVersion
}
dependencies {
compileOnly "com.querydsl:querydsl-jpa:${querydslVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor(
"com.querydsl:querydsl-apt:${querydslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:${hibernateJPAVersion}",
"javax.annotation:javax.annotation-api:${javaxAnnotationVersion}",
"org.projectlombok:lombok"
)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 Gradle、QueryDSL 和 Lombok 一起使用是一项棘手的工作,但幸运的是,很少有插件可以让这一切变得简单。这是有效的代码。
io.franzbecker.gradle-lombok
和com.ewerk.gradle.plugins.querydsl
是正确运行所有 3 个插件所需的插件。Working with Gradle, QueryDSL and Lombok together is a tricky job, but luckily there are few plugins which makes it easy. Here is the code that works.
io.franzbecker.gradle-lombok
andcom.ewerk.gradle.plugins.querydsl
are the required plugins to work all 3 correctly.