gradle 的 QueryDSL 问题

发布于 2025-01-10 07:40:24 字数 6048 浏览 0 评论 0原文

我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔日梦未散 2025-01-17 07:40:24

将 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 个插件所需的插件。

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.

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-lombok and com.ewerk.gradle.plugins.querydsl are the required plugins to work all 3 correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文