달리는 두딘

Intellij에서 QueryDSL 오류 (cannot find symbol Q class) 본문

지식노트/험난한 여정

Intellij에서 QueryDSL 오류 (cannot find symbol Q class)

디두딘 2023. 7. 19. 21:07

반갑습니당
오랜만에 포스팅이군여
 
개발 도중 빡쳐서 돌아왔습니다 하하
진짜 Querydsl 때문에 돌아버리겠음
 

 
뭔 빌드 할 때마다 에러가 이렇게 많이 나~!!!!!
미칑럼
맨날 빨간줄 파티야!!!!!!!!!!!
 
모두들 저같은 고통 겪지 마시라고 공유합니다.
 


1. build.gradle

1. dependencies에 추가

//querydsl 추가
implementation 'com.querydsl:querydsl-jpa'
implementation 'com.querydsl:querydsl-core'

2. 쿼리 파라미터 로그 남기기

//로그 남길때
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.5.8'

3. build.gradle 최상단에 추가

buildscript {
	ext {
		queryDslVersion = "5.0.0"
	}
}

4. plugins에 아래 코드 추가

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

5. build.gradle 최하단에 아래 코드 모두 추가

//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
}
//querydsl 추가 끝

인텔리제이 설정

Preferences - Build, Execution, Deployment - Build Tools - Gradle에 가서

  • build and run using을 gradle에서 IntelliJ Idea로 변경
  • Run tests using을  gradle에서 IntelliJ Idea로 변경

롬복 설정

Preferences - Annotation Processors 검색해서 Enable


Gradle 설정

인텔리제이 우측 탭 Gradle - Tasks - Other - compileQueryDsl
우측에 Gradle이 보이지 않는다면, 상단바 View - Tool Windows - Gradle 
 
build가 끝나면 프로젝트에 build - generated - querydsl 안에 생성되었을 것!!!!!!
 
 
아 그리고 가끔 intellij 버전과 충돌나는 경우도 있다고들 하니까
다운그레이드 하는 것도 방법......