Spring Framework
[QueryDSL] STS에서 Gradle 사용 시 QueryDSL QClass 생성 설정
헤르메스의날개
2022. 3. 27. 22:43
728x90
1. build.gradle
/* Eclipse 설정 시작 ----------------------------*/
def querydslDir = "src/main/generated"
querydsl {
library = "com.querydsl:querydsl-apt"
jpa = true
querydslDefault = true
querydslSourcesDir = querydslDir
}
//에디터 설정
sourceSets {
main {
java {
srcDirs = ['src/main/java', querydslDir]
}
}
}
//컴파일 클래스 패스에 넣음.
configurations {
querydsl.extendsFrom compileClasspath
}
//어노테이션 프로세서와 맞물려서 빌드시 생성
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
/* Eclipse 설정 종료 ----------------------------*/
2. [프로젝트] > [Properties] > [Java Build Path] > Source 탭
Add Folder > Create New Folder
3. Gradle Tasks > build > Run Gradle Tasks
4. build.gradle 전체 소스
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
//querydsl 추가
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
id 'java'
}
group = 'com.mile'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
def querydslVersion = '4.4.0'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
//querydsl.extendsFrom compileClasspath
}
repositories {
mavenLocal() // 로컬 저장소 사용
mavenCentral() // 원격 저장소 사용
jcenter()
google()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0'
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.2'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2'
// Querydsl
implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-core', version: querydslVersion
// thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
runtimeOnly 'com.h2database:h2'
annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
annotationProcessor group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion, classifier: 'jpa'
annotationProcessor("jakarta.persistence:jakarta.persistence-api")
annotationProcessor("jakarta.annotation:jakarta.annotation-api")
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
/* Eclipse 설정 시작 ----------------------------*/
def querydslDir = "src/main/generated"
querydsl {
library = "com.querydsl:querydsl-apt"
jpa = true
querydslDefault = true
querydslSourcesDir = querydslDir
}
//에디터 설정
sourceSets {
main {
java {
srcDirs = ['src/main/java', querydslDir]
}
}
}
//컴파일 클래스 패스에 넣음.
configurations {
querydsl.extendsFrom compileClasspath
}
//어노테이션 프로세서와 맞물려서 빌드시 생성
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
/* Eclipse 설정 종료 ----------------------------*/
/* IntelliJ 설정
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
clean {
delete file(querydslDir) // 인텔리제이 Annotation processor 생성물 생성위치
}
task cleanGeneatedDir(type: Delete) { // 인텔리제이 annotation processor 가 생성한 Q클래스가 clean 태스크로 삭제되는 게 불편하다면 둘 중에 하나를 선택
delete file(querydslDir)
}
*/
/* IntelliJ 설정
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
clean {
delete file(querydslDir) // 인텔리제이 Annotation processor 생성물 생성위치
}
task cleanGeneatedDir(type: Delete) { // 인텔리제이 annotation processor 가 생성한 Q클래스가 clean 태스크로 삭제되는 게 불편하다면 둘 중에 하나를 선택
delete file(querydslDir)
}
*/
728x90