AnnotationProcessor Querydsl java.lang.NoClassDefFoundError


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

1 Like

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.

1 Like

I am facing the similar issue like this only. The issue I am facing:

  • What went wrong:
    Execution failed for task ‘:generateQueryDSL’.

Annotation processor ‘com.querydsl.apt.jpa.JPAAnnotationProcessor’ not found

Can you please help me out how to manually add the annotation processor configuration. I am using querydsl 4.1.4 version. already adding the JAVAX Persistence.

Below is the sample:

implementation group: ‘org.hibernate.javax.persistence’, name: ‘hibernate-jpa-2.1-api’, version: ‘1.0.2.Final’

implementation group: ‘com.querydsl’, name: ‘querydsl-maven-plugin’, version: ‘4.1.4’
implementation group: ‘com.querydsl’, name: ‘querydsl-core’, version: ‘4.1.4’
implementation group: ‘com.querydsl’, name: ‘querydsl-apt’, version: ‘4.1.4’
implementation group: ‘com.querydsl’, name: ‘querydsl-jpa’, version: ‘4.1.4’
implementation group: ‘com.querydsl’, name: ‘querydsl-collections’, version: ‘4.1.4’
implementation group: ‘com.querydsl’, name: ‘querydsl-codegen’, version: ‘4.1.4’

task generateQueryDSL(type: JavaCompile, group: ‘build’, description: ‘Generates the QueryDSL query types’) {
source =
classpath = configurations.compileClasspath
options.compilerArgs = [
options.warnings = false
destinationDir =

I added the following lines :

annotationProcessor group: ‘com.querydsl’, name: ‘querydsl-apt’, classifier: ‘jpa’
annotationProcessor ‘jakarta.persistence:jakarta.persistence-api’

My versions are defined in a platform module , you can add them to the declarations.

1 Like

Hi Venkat, were able to solve the issue? i am facing the same issue. Can you please help me on the same?

I don’t have a new task dedicated to querydsl generation
I’m relying to the annotationProcessor scope (i’m currently using kotlin kapt but using the java annotationProcessor is OK too)

In my project I have defined

dependencies {
kapt group: ‘com.querydsl’, name: ‘querydsl-apt’, classifier: ‘jpa’
kapt ‘javax.persistence:javax.persistence-api’


Before that these annotations became standard Gradle, I used GitHub - tbroyer/gradle-apt-plugin: [OBSOLETE] Gradle plugin making it easier/safer to use Java annotation processors
It is deprecated but you can still read the README to have a better understanding