[Spring JPA] QueryDsl와 Gradle 그리고 AnnotationProcessor
2021. 2. 19. 18:51
반응형
발단>
1. Gradle 버전이 4.*에서부터 5.* 최근에는 6.7까지 출시
2. Spring boot 2.3부터 Gradle 버전 6.3 이상을 요구
개발환경>
spring boot 2.4
Gradle 6.7.1
인텔리제이에서 프로젝트를 진행하면서 QueryDsl을 이용해서 생성한 Q클래스를 생성하였다.
빌드시 에러가 발생함.
에러 메시지>
package com.querydsl.core.types does not exist
수정 전 build.gradle>
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
id 'java'
}
group = 'com.jiyoon'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.rest-assured:rest-assured:4.3.3'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
implementation 'com.querydsl:querydsl-jpa'
implementation 'com.querydsl:querydsl-apt'
}
test {
useJUnitPlatform()
}
def querydslSrcDir = "src/main/generated"
querydsl {
library = "com.querydsl:querydsl-apt"
jpa = true
querydslSourcesDir = querydslSrcDir
}
sourceSets {
main.java.srcDirs = ['src/main/java', querydslSrcDir]
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
Gradle Plugin “com.ewerk.gradle.plugins.querydsl” 로 설정하였다. 해당 프로젝트에서는 빌드 시 에러가 발생
수정 후 build.gradle>
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.jiyoon'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
def querydslVersion = '4.3.1'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.rest-assured:rest-assured:4.3.3'
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.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
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")
}
test {
useJUnitPlatform()
}
clean {
delete file('src/main/generated') // 인텔리제이 Annotation processor 생성물 생성위치
}
참고
Gradle 5.0이상 & IntelliJ 2020.* 사용 시
[gradle] 그레이들 Annotation processor 와 Querydsl
problem-with-generating-querydsl-classes-with-gradle
728x90
반응형
'web > Spring' 카테고리의 다른 글
[Spring Web MVC] 컨트롤러 클래스, 뷰 구현 (2) | 2021.11.24 |
---|---|
[Spring] 의존성 주입 애노테이션 @Autowired @Resource @Inject (0) | 2021.11.22 |
[Spring JPA/Rest API/AWS] 1. Spring Boot 프로젝트 생성 및 설정 (2) | 2020.05.09 |
[Spring JPA] @RestController / @ResponseBody / @RequestBody (0) | 2020.05.04 |
[Spring JPA] Repository 기본 메소드 (0) | 2020.05.02 |
Written by ner.o
개발자 네로의 개발 일기,
자바를 좋아합니다 !
댓글 개