[Error] Querydsl Cannot find symbol
by coco3o반응형
코드로 배우는 스프링부트 웹프로젝트 서적을 공부하던 중에
Querydsl이 셋팅된 프로젝트에서 gradle build 시 QClass가 있는 build/generated/querydsl package를
처음 만들면 문제 없이 빌드 되었지만, 그 이후 빌드 시 아래와 같은 에러를 뱉으며 빌드가 되지 않는 문제가 있었습니다.
> Task :compileQuerydsl FAILED
java:13: error: cannot find symbol
public class Guestbook extends BaseEntity {
^
symbol: class BaseEntity
Note: Running JPAAnnotationProcessor
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileQuerydsl'.
> java.lang.IllegalStateException: Found no type for BaseEntity
셋팅한 build.gradle은 아래와 같습니다.
plugins {
id 'org.springframework.boot' version '2.5.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
}
group = 'org.coco'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.querydsl:querydsl-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-java8time'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
여기서 하나만 추가해주면 문제는 사라집니다.
plugins {
id 'org.springframework.boot' version '2.5.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'war'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
}
group = 'org.coco'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'mysql:mysql-connector-java'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.querydsl:querydsl-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-java8time'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
/**
* comileQuerydsl.doFirst 추가
*/
compileQuerydsl.doFirst {
if(file(querydslDir).exists() )
delete(file(querydslDir))
}
이 후, 빌드할 때마다 compileQuerydsl 작업 전에 generated/querydsl package를 삭제하고,
다시 컴파일해서 생성하도록 해서 문제는 없어졌습니다.
참고
반응형
'📌ETC > Error' 카테고리의 다른 글
블로그의 정보
슬기로운 개발생활
coco3o