on
Springboot Querydsl 설정
Springboot Querydsl 설정
build.gradle querydsl 플러그인 추가
plugins { id "com.ewerk.gradle.plugins.querydsl" version "1.0.10" }
build.gradle querydsl 라이브러리 추가
dependencise { implementation 'com.querydsl:querydsl-jpa' }
querydsl 빌드 설정 추가
// querydsl 추가 def querydslDir = "$buildDir/generated/querydsl" querydsl { jpa = true querydslSourcesDir = querydslDir } sourceSets { main.java.srcDir querydslDir } configurations { querydsl.extendsFrom compileClasspath } compileQuerydsl { options.annotationProcessorPath = configurations.querydsl }
프로젝트 빌드 새로고침
Reload gradle projects
빌드 성공 확인
Entity 클래스 생성
QEntity를 생성하기 위한 Entity 클래스를 생성합니다
compileQuerydsl 실행
생성된 Entity를 QEntity로 생성하기 위해 other > compileQuerydsl을 실행합니다
build.gradle에 설정된 querydslDir 디렉토리에 QEntity 파일이 생성됩니다
QEntity 생성 실패
Third-party 라이브러리와 Gradle 버전이 호환되지 않는 문제 발생
현재 사용중인 Gradle Version 7.3
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart) Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
build.gradle querydsl library 설정 추가
위와 같이 최신 버전의 Gradle 사용 시 complieQuerydsl 에러가 발생하는 경우
querydsl-apt library 설정을 추가해 주시면 해결하실 수 있습니다
library = "com.querydsl:querydsl-apt"
querydsl-apt(APT based Source code generation for Querydsl querydsl : 소스코드로 변환해주는 라이브러리)
querydsl { library = "com.querydsl:querydsl-apt" jpa = true querydslSourcesDir = querydslDir }
QEntity 생성
buildDir/generated/querydsl 경로에
정상적으로 QEntity가 생성된 것을 확인하실 수 있습니다
(QEntity 파일이 생성된 것은 확인해야만 합니다)
Generated 되어진 소스는 세부 내용이 변경될 수 있어
Git에 포함되지 않도록 .gitignore 파일에 추가해주시거나
현재 설정된 경로처럼 기본적으로 ignore 되어지는
build 하위 경로에 QEntity가 생성되도록 설정을 해주시면 됩니다
from http://wjjeong.tistory.com/59 by ccl(A) rewrite - 2021-12-11 16:02:10