gpt4 book ai didi

java - Gradle 的 QueryDSL 问题

转载 作者:行者123 更新时间:2023-12-05 05:45:50 28 4
gpt4 key购买 nike

我正在将 QueryDSL 与 Lombok 和 gradle 结合使用。 Q 类正在生成,IDEA 也可以看到它们并且没有编译器错误但是当我尝试执行 gradle build 时我得到:

error: cannot find symbol
import QRole;

因此生成了文件,但 gradle build like 看不到它们。我发现的所有解决方案都不起作用,无论我做什么,我仍然会收到此错误。这是我的 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"
)
}

最佳答案

同时使用 Gradle、QueryDSL 和 Lombok 是一项棘手的工作,但幸运的是,几乎没有插件可以让这一切变得简单。这是有效的代码。

plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'idea'
id 'io.franzbecker.gradle-lombok' version '5.0.0'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
}

querydsl {
library = 'com.querydsl:querydsl-apt:5.0.0'
jpa = true
}

configurations {
querydsl.extendsFrom implementation, compileClasspath
}

compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}

project.afterEvaluate {
project.tasks.compileQuerydsl.options.compilerArgs = [
"-proc:only",
"-processor", project.querydsl.processors() +
',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
]
}

sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/querydsl/java']
}
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.querydsl:querydsl-jpa:5.0.0'
}

io.franzbecker.gradle-lombokcom.ewerk.gradle.plugins.querydsl 是所有 3 个正确工作所需的插件。

关于java - Gradle 的 QueryDSL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71280005/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com