스프링부트 2.6.7, java 8, gradle 7.4.X querydsl 설정 방법 공유
2238
18 asked
시행착오 끝에 성공해가지고 공유합니다.
(저의 프로젝트 gradle 버전은 7.4대입니다.)
첫번째로 build.gradle 입니다.
의존성에 나머지 부분은 무시하셔도 되고 10번대가 querydsl설정부분입니다.
/* 10-1. querydsl version 정보 추가 */
buildscript {
ext {
queryDslVersion = "5.0.0";
}
}
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
/* 10-2. querydsl plugin 추가 */
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
group = 'com.shop'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
/* 10-3. querydsl */
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
/* 1. web */
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
/* 2. 배포시 내장톰캣을 사용하지 않을거라는 dependency */
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
/* 3. lombok */
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
/* 4. devtools */
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
/* 5. thymeleaf */
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
/* 6. mybatis */
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.3'
/* 7. MariaDB */
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
/* 8. JDBC */
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
/* 9. JPA */
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
/* 10-4. querydsl dependencies 추가 */
implementation "com.querydsl:querydsl-jpa:${queryDslVersion}"
annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}"
/* 11. thymeleaf-layout-dialect */
implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '3.0.0'
/* 12. spring-boot-starter-security */
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
/* 13. validation(Bean Validation) */
implementation 'org.springframework.boot:spring-boot-starter-validation'
/* 14. modelmapper */
implementation group: 'org.modelmapper', name: 'modelmapper', version: '2.3.9'
/* 15. thymeleaf-extras-springsecurity5 */
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5'
/* 16. spring-security-test */
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
/* 10-5. querydsl에서 사용할 경로 지정*/
def querydslDir = "src/main/generated"
/* 10-6. JPA사용 여부와 사용할 경로를 지정*/
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
/* 10-7. build시 사용할 SourceSet 추가 */
sourceSets {
main.java.srcDir querydslDir
}
/* 10-8. querydsl이 complieClasspath를 상속하도록 설정 */
configurations {
querydsl.extendsFrom compileClasspath
}
/* 10-9. querydsl 컴파일시 사용할 옵션 설정 */
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
-> build.gradle에 이렇게 적구요.
-> 프로젝트 우클릭 gradle -> represh gradle project를 한번 해주고 진행합니다.
두번째
-> gradle task -> build -> classes를 실행
-> src/main 하위에 generated라는 폴더가 생기고 그 하위에 Q파일이 생긴걸 볼 수 있다.
-> 하지만 추가로 더 해줘야 할 작업이 있다. 프로젝트에서 저 경로를 추가해줘야 위에서 사용할 수 있다.
아무 컨트롤러에서 Q파일을 불러올려고하면 찾지를 못한다. 그래서 경로를 추가해줘야한다.
-> 프로젝트 우클릭 -> Build Path -> Configure Build Path 로 들어간다.
-> Java Build Path -> Source 탭에 보면 프로젝트에 우리가 추가한 generated 폴더가 보이지 않는다.
-> Add Folder... 클릭 -> 우리가 만든 generated도 체크를 해주고 확인을 눌르고 Apply하면 프로젝트 위에도 우리가만든 q파일이 들어있는 폴더 generated가 생긴다.
-> 이제 아무 컨트롤러에 들어가서 Q를 치고 자동완성을 해보면 접근할 수 있는걸 볼 수 있고 이제 다음 강의를 들으러 가면된다.
끝.....
이상 스프링부트 2.6.7에서 querydsl 적용 방법이었습니다.
추가로 보통 이것저것 찾아봤는데 java 11버전으로 많이들 하시더라구요 근데 제꺼는 java8도 돌아갑니다
(제가 java8....)
Answer 3
1
감사합니다
서칭중 찾게 되었는데 이대로 하니 되네요
저는 generated 폴더 apply는 안해도 동작했습니다.
강의 관련 외 질문입니다.
0
64
2
SpringBoot4 + Hibernate7 모듈 등록 방법 공유
0
85
1
BeanCreationException
0
86
3
Update 후 UpdateMemberResponse 매핑할 때
0
46
1
트랜잭션을 사용 안 할 때 커넥션은 언제 가져오나요?
0
97
2
페이징 + 검색조건 관련해서 질문드립니다.
0
70
1
Query Dsl Q파일 질문입니다.
0
81
1
루트 쿼리라는것은
0
58
1
메서드를 분리하는 기준
0
61
1
findAllWithMemberDelivery 메서드 질문드립니다.
0
108
3
연관관계 매핑을 안 쓸 경우, 사용해야 하는 전략
0
83
2
fetch join과 영속화와 OSIV의 관계
0
83
2
Distinct 사용 전 결과에 대한 의문
0
113
2
레포지토리 계층에서의 트랜잭션에 대한 의문
0
55
1
영속성 컨텍스트 생명주기의 신기한 부분이 있습니다.
0
77
2
dto 필드 속 엔티티 여부
0
58
1
뷰템플릿 사용 시
0
76
2
Result 클래스 관련 질문
0
56
1
@PostConstruct 프록시 관련 질문드립니다
0
85
1
DTO 대신 Form 사용은 안되나요?
0
133
1
OSIV ON 상태일 때
0
95
1
fetch join VS fetch join 페이징 궁금증
0
179
2
양방향 연관관계 알아보는 법?
0
104
1
16강 17강 간단 정리 이게 맞을까요 ?
0
165
2

