본문으로 바로가기

[JPA] Querydsl 설정

category TILJPA 3년 전

Querydsl

SQL, JPQL을 코드로 작성할 수 있게 해주는 빌더 API
  • 컴파일 시점에 문법 오류 발견할 수 있음
  • 동적 쿼리
  • 편리하고 실용적

 

사용법

1. 의존성 추가

  • build.gradle
buildscript {
	ext {
		querydslVer = '4.4.0'
		querydslPluginVer = '1.0.10'
	}
	
	dependencies {
		classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:${querydslPluginVer}"
	}
}

plugins {
	id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

apply plugin: 'com.ewerk.gradle.plugins.querydsl'

def querydslDir = 'src/main/generated'
querydsl {
    library = "com.querydsl:querydsl-apt"
    jpa = true
    querydslSourcesDir = querydslDir
}

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', querydslDir]
        }
    }
}

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}

configurations {
    querydsl.extendsFrom compileClasspath
}

dependencies {
		implementation 'com.querydsl:querydsl-jpa:4.4.0'
    implementation 'com.querydsl:querydsl-apt:4.4.0'
}
  • querydsl 플러그인 추가
  • 라이브러리 dependency 추가
  • querydsl에서 사용할 경로 선언
  • querydsl 설정 추가
  • build 시 사용할 sourceSet 추가
  • querydsl이 compileClassPath를 상속하도록 설정
  • querydsl 컴파일 시 사용할 옵션을 설정

 

2. complieQuerydsl task 실행

[ Eclipse / Spring Tool Suite ]

  • IDE 사용 시 → gradle 탭에서 task를 찾아서 실행
  • 터미널 사용 시 → 프로젝트 루트 폴더에서 ./gradlew compileQuerydsl

 

[ IntelliJ ]

  • Gradle > Tasks > build > clean
  • Gradle > Tasks > other > compileQuerydsl

TILJPA카테고리의 다른글

[JPA] 데이터베이스 스키마 자동 생성하는 방법  (0) 2022.05.07
[JPA] annotation 종류  (0) 2022.05.06
[JPA] N+1 문제  (0) 2022.04.19
[JPA] JPA란?  (0) 2022.04.19