AnnotationProcessor Querydsl java.lang.NoClassDefFoundError

(François) #1


I have a multiproject and some of my subprojects uses JPA over Querydsl. To do that, at compile time we need to generate the querydsl classes (Q) using APT

I tried with and without the gradle-apt-plugin. During compile time I got the following error

Caused by: java.lang.NoClassDefFoundError: javax/persistence/Entity
    at com.querydsl.apt.jpa.JPAAnnotationProcessor.createConfiguration(
    at com.querydsl.apt.AbstractQuerydslProcessor.process(

I have the following build.gradle for my subproject

project(':echanges:infrastructure:jpa-db-adapter') {
  apply plugin: 'jacoco'
  apply plugin: 'idea'
  apply plugin: 'net.ltgt.apt'
  apply from:   "$rootDir/gradle/org.gfc.integtest.gradle"

  tasks.withType(JavaCompile) {
      options.annotationProcessorGeneratedSourcesDirectory = file("$projectDir/src/generated3/java")
  dependencies {

    annotationProcessor "com.querydsl:querydsl-apt:$querydslVersion:jpa"

    compile project(':echanges:application-core:core')
    implementation project(':commons')

    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    compile 'javax.inject:javax.inject:1'
    compile "com.querydsl:querydsl-jpa:$querydslVersion"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"

    testCompile 'org.springframework.boot:spring-boot-starter-test'
    integrationTestCompile ''

sourceSets {
    main {
        java {
            srcDirs = ["$projectDir/src/main/java", "$projectDir/src/generated/java"]


The JPA annotations are declared inside the hibernate-jpa-2.1-api. The spring data jpa pull this jar transitive

Thanks for your help

(Stefan Oehme) #2

Looks like the queryDsl processor depends on javax.persistence, but doesn’t declare a dependency on it. To work around, you’ll have to manually add it to the annotationProcessor configuration. Consider opening a bug for queryDsl. They should add a dependency on it so it automatically brings it in for processing.

Note that the processor path (used for loading annotation processors and compiler plugins) and the compile classpath (what your code is allowed to link against) are two separate and different things. Dependencies on one are not visible to the other.