코딩하는 털보

QueryDsl cannot find symbol 본문

IT Study/JPA

QueryDsl cannot find symbol

이정인 2023. 2. 13. 17:07

QueryDSL 적용후 빌드에서 아래와 같은 에러 발생

/Users/E8L-20220010/IdeaProjects/dataIngest/agentManager/build/generated/querydsl/kr/co/e8ight/ndxpro/agentManager/domain/QAgentHistory.java:39: error: cannot find symbol
    public QAgentHistory(Path<? extends AgentHistory> path) {
                                        ^
  symbol:   class AgentHistory
  location: class QAgentHistory

gradle build task는 여러 task를 통해 실행되는데 (compile, bootJar, jar, test 등등)

구글링 해본 사람들은 아래와 같이 buildscript를 등록할 것이기 때문에 build과정에 querydsl 관련 task가 자동으로 추가된다.

buildscript {
    ext {
        queryDslVersion = "5.0.0"
    }
}

추가되는 task는 compileQuerydsl 이며 compileJava 이전에 실행된다.

문제는 이전에 생성되어있던 Qclass들이 compileQuerydsl을 방해하는 것으로 보인다.

이렇게 생각한 이유는 clean task로 build 디렉토리를 삭제하거나 Qclass를 삭제하거나 cleanQuerydslSourcesDir을 먼저 실행하는 경우 문제없이 잘 되기 때문.

그래서 compileQuerydsl이 동작하기 전에 이전에 생성했던 Qclass들을 제거하고 새로 생성할 수 있도록 cleanQuerydslSourcesDir task가 먼저 실행되도록 했다.

compileQuerydsl {
    dependsOn(cleanQuerydslSourcesDir)
    options.annotationProcessorPath = configurations.querydsl
}

이렇게 하면 문제는 해결된다만 이전의 Qclass들이 왜 문제가 되는지는 모르겠다.

Comments