GradlecompileQuerydsl 生成的目录结构存在问题

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

我一边看在线讲座一边继续,现在我不确定是版本改变了还是什么,但即使我运行compileQuerydsl,也只创建了最高目录,而不是目标模型。 我的build.gradle和模型如下。如果您能告诉我原因,我将不胜感激。

这是build.gradl

plugins {
id 'java'
id 'org.springframework.boot' version '3.1.3'
id 'io.spring.dependency-management' version '1.1.3'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.mariadb.jdbc:mariadb-java-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'

implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2' // import javax.persistence.Entity;
implementation 'org.hibernate:hibernate-core:6.1.7.Final'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'

compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'

//QueryDSL 추가
implementation 'com.querydsl:querydsl-jpa:5.0.0'
//    annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: '5.0.0'
implementation 'com.querydsl:querydsl-apt:5.0.0'
}

这是ExampleTable.java(模型)

import jakarta.persistence.\*;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
public class ExampleTable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

private String name;

private int age;

public ExampleTable(Long id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}

public ExampleTable() {

}
}

这是我运行compileQuerydsl 的结果。 enter image description here

java spring-boot dsl
1个回答
0
投票

使用此 build.gradle 生成 Query 类:

 plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.3'
    id 'io.spring.dependency-management' version '1.1.3'
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '17'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }

    querydsl.extendsFrom compileClasspath
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    compileOnly 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    //QueryDSL 
    implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
    implementation  "com.querydsl:querydsl-apt:5.0.0:jakarta"
    annotationProcessor(
            "com.querydsl:querydsl-apt:5.0.0:jakarta",
            "jakarta.persistence:jakarta.persistence-api:3.1.0",
            "org.projectlombok:lombok"
    )
}

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

def queryDslSourceDirectory = 'src/main/querydsl/generated'
querydsl {
    jpa = true
    querydslSourcesDir = queryDslSourceDirectory
}

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}

将以下行添加到配置中

querydsl.extendsFrom compileClasspath

在依赖项部分中需要进行以下更改:

 annotationProcessor(
            "com.querydsl:querydsl-apt:5.0.0:jakarta",
            "jakarta.persistence:jakarta.persistence-api:3.1.0",
            "org.projectlombok:lombok"
    )

最后添加:

def queryDslSourceDirectory = 'src/main/querydsl/generated'
querydsl {
    jpa = true
    querydslSourcesDir = queryDslSourceDirectory
}

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}
© www.soinside.com 2019 - 2024. All rights reserved.