Gradle 7.4.2 的 Querydsl 配置

问题描述 投票:0回答:1

我有一个 Gradle 项目,我想在其中使用 querydsl 实现 Java 类。我尝试过这个实现:

plugins {
    id 'org.springframework.boot' version '2.6.7'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'test'
version = '0.0.1'
sourceCompatibility = '17'

ext {
    set('springCloudVersion', "2021.0.2")
    queryDslVersion = '5.0.0'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.hibernate.validator:hibernate-validator'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'joda-time:joda-time:2.10.14'
    implementation 'org.springframework.boot:spring-boot-starter-hateoas:2.6.7'
    implementation 'org.postgresql:postgresql'
    implementation 'org.jadira.usertype:usertype.core:7.0.0.CR1'
    implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.2'
    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'com.google.code.gson:gson:2.9.0'

    // QueryDSL
    implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
    annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jpa"
    testImplementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
    testAnnotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jpa"
    
    // Lombok
    compileOnly 'org.projectlombok:lombok:1.18.24'
    annotationProcessor 'org.projectlombok:lombok:1.18.24'
    testCompileOnly 'org.projectlombok:lombok:1.18.24'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
    // Swagger
    implementation 'org.springdoc:springdoc-openapi-ui:1.6.8'

    implementation 'org.liquibase:liquibase-core'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

但是不会生成 JPA 类。我得到例外:

import com.test.domain.QTransaction;
                       ^
  symbol:   class QTransaction
  location: package com.test.domain

您知道实施此操作的正确方法是什么吗?

java jpa gradle spring-data-jpa querydsl
1个回答
0
投票

Spring Cloud

2021.0.8
/Spring Boot
2.6.15
和 Gradle
8.3

的工作配置
implementation 'com.querydsl:querydsl-jpa:5.0.0'
annotationProcessor 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final'
annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jpa'
© www.soinside.com 2019 - 2024. All rights reserved.