AnnotationProcessor Querydsl java.lang.NoClassDefFoundError

Hello,

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(JPAAnnotationProcessor.java:37)
    at com.querydsl.apt.AbstractQuerydslProcessor.process(AbstractQuerydslProcessor.java:79)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
    at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
    at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
    at com.sun.tools.javac.main.Main.compile(Main.java:523)

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 'com.oracle:ojdbc6:11.2.0.3'
}

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 = sourceSets.main.java
classpath = configurations.compileClasspath
options.compilerArgs = [
‘-proc:only’,
‘-processor’,
‘com.querydsl.apt.jpa.JPAAnnotationProcessor’
]
options.warnings = false
destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}

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