본문 바로가기

Back-end/QueryDsl

[QueryDsl] QueryDsl Spring boot 3 이상 설정

queryDsl은 사용하기가 정말 편하지만 Configuration이 좀 중구난방이라무엇을 사용하는게 좋을지 매번 헷갈려서 이번에 사이드프로젝트를 진행하면서 정리를 했다.

 

✅Plugin 정보

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.3.6'
    id 'io.spring.dependency-management' version '1.1.7'
}

 

Gradle 5.0 이상 혹은 IntelliJ 2020.x를 사용하는 경우, Gradle로 프로젝트를 빌드할 때 “동일한 Q파일을 생성하지 말라”는 에러 메시지가 나타나며, 배포 작업에서 문제가 발생합니다.

이 배포 관련된 문제로 com.ewerk.gradle.plugins.querydsl 플러그인을 사용 하지않는다.

 

✅ Dependencies

// QueryDSL
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" // 수정
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

 

✅ QueryDsl 빌드 옵션

// ===  QueryDsl 빌드 옵션 (선택) ===
def querydslDir = layout.buildDirectory.dir("generated/querydsl").get().asFile
sourceSets {
    main.java.srcDirs += [ querydslDir ]
}

tasks.withType(JavaCompile).configureEach {
    options.getGeneratedSourceOutputDirectory().set(file(querydslDir))
}

clean.doLast {
    file(querydslDir).deleteDir()
}


clean {
    delete file('src/main/generated')
}

 

위에서는 2가지에 대해 deprecated된 부분에 대해 수정

def generated = "$buildDir/generated/querydsl" 와 같이 작성하면 deprecated 가 되어서 부분을
def generated = layout.buildDirectory.dir("generated/querydsl").get().asFile 와 같이 변경

 

tasks.withType(JavaCompile) {
    options.annotationProcessorGeneratedSourcesDirectory = file(querydslDir)
}

 

그리고 이부분을

 

tasks.withType(JavaCompile).configureEach {
    options.getGeneratedSourceOutputDirectory().set(file(querydslDir))
}

 

이와같이 변경