Querydsl Annotation Processor issue after upgrade to Gradle 5

Michal Plewka picture Michal Plewka · Dec 24, 2018 · Viewed 8.4k times · Source

I have a gradle script which generates querydsl classes from Mongo annotated entities. It was working so far, but after upgrade to Gradle 5 I have a problem with:

* What went wrong:
Execution failed for task ':myproject-common:compileQuerydsl'.
Annotation processor 'org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor' not found

Please find my gradle.build script below. Any ideas what could be wrong? I read that there was change in Gradle 5 that annotation processors are not used by default during compilation and annotationProcessor declaration should be added but when I add it to dependencies the same error occurs.

plugins {
    id 'org.springframework.boot' version '2.0.4.RELEASE'
    id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}
repositories {
    mavenCentral()
}
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
jar {
    enabled = true
    baseName = 'myproject-common'
    version =  '0.0.1-SNAPSHOT'
}
// do no package commons into fat jar
bootJar {
    enabled = false
}
querydsl {
    library = 'com.querydsl:querydsl-apt:4.1.4'
    querydslSourcesDir = 'src/main/querydsl'
    springDataMongo = true
}
sourceCompatibility = 11.0
targetCompatibility = 11.0
sourceSets {
    main {
        java {
            srcDirs = ['src/main/java', 'src/main/querydsl']
        }
    }
}
dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.data:spring-data-mongodb")
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("com.fasterxml.jackson.datatype:jackson-datatype-    jsr310:2.8.6")
    compile("com.google.guava:guava:23.0")
    compile("commons-io:commons-io:2.5")
    compile("org.aspectj:aspectjweaver:1.8.9")
    compile("org.apache.commons:commons-lang3:3.5")
    compile("commons-collections:commons-collections:3.2.2")
    compile("org.javamoney:moneta:1.1")
    compile("com.fizzed:rocker-runtime:1.2.0")
    compile("com.querydsl:querydsl-core:4.1.4")
    compile("com.querydsl:querydsl-mongodb:4.1.4")
    compile("com.querydsl:querydsl-apt:4.1.4")
    compile("com.codepoetics:protonpack:1.15")

    testCompile("org.springframework.boot:spring-boot-starter-test")
    testCompile("org.assertj:assertj-core:3.7.0")
}

Answer

Michal Plewka picture Michal Plewka · Dec 26, 2018

I have finally found a workaround. Querydsl's lack of compatibility with Gradle 5 is reported here as a bug: https://github.com/ewerk/gradle-plugins/issues/108

Workaround is to add to gradle script:

compileQuerydsl {
    options.annotationProcessorPath = configurations.querydsl
}