[JPA] gradle의 compileQuerydsl task 예외

code4109·2022년 11월 8일
0

querydsl 연습중 q class를 생성하기 위해 compileQuerydsl task를 실행하니 아래의 예외가 발생한다.

Unable to load class 'com.mysema.codegen.model.Type'.

This is an unexpected error. Please file a bug containing the idea.log file.

설정은 아래와 같다.

plugins {
	...
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
    ...
}
...
dependencies {
    ...
    implementation 'com.querydsl:querydsl-jpa'
	...
}
...
def querydslDir = "$buildDir/generated/querydsl"

querydsl {
    jpa = true
    querydslSourcesDir = querydslDir
}
sourceSets {
    main.java.srcDir querydslDir
}
compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}
configurations {
    querydsl.extendsFrom compileClasspath
}

결론은 Spring boot 버전이 바뀌면서 QueryDSL 설정도 바뀌었다.
아래와 같이 설정을 수정했다.

dependencies {
    ...
    // querydsl-apt를 추가하고 querydsl-jpa와 함께 명시적으로 버전을 표시
    implementation 'com.querydsl:querydsl-jpa:5.0.0'
    // Annotation Processing Tool, querydsl 관련 코드 생성(codegen) 기능 제공
    annotationProcessor 'com.querydsl:querydsl-apt:5.0.0'
	...
}
...
configurations {
	// 아래 설정이 있는 경우 dependencies에 annotationProcessor로 설정된 라이브러리를 
    // IntelliJ에 Gradle Imported라는 이름의 프로파일인 어노테이션 프로세서로 등록하기 위해 어노테이션 프로세싱 기능을 활성화하는 것을 자동으로 구성함
    compileOnly {
        extendsFrom annotationProcessor
    }
    querydsl.extendsFrom compileClasspath
}

task도 잘 실행되고 q class도 잘 만들어짐

궁금한 점

  • 버전을 지정하지 않았을 때도 5.0.0을 받아 오던데 task는 실패했다. 그런 버전을 기입하니 잘 된다. build.gradle 파일 자체로 뭔가 하는게 있나.

0개의 댓글