12

I’m trying to integrate QueryDSL, Gradle and Springboot in versions from title. I added annotationProcessors to gradle but Intellij is still not generating the QClasses. I tried sugesstions from community to use the plugin ‘gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin’ but this did not help.

dependencies{
   annotationProcessor("org.projectlombok:lombok:1.18.4")
   annotationProcessor("com.querydsl:querydsl-apt:4.2.1")
   annotationProcessor("org.springframework.boot:spring-boot-starter-data-jpa:2.1.1.RELEASE")

   compileOnly("org.projectlombok:lombok:1.18.4")
   implementation("com.querydsl:querydsl-jpa:4.2.1")
   implementation("com.querydsl:querydsl-apt:4.2.1:jpa")
   implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.1.1.RELEASE")
   implementation("org.springframework.boot:spring-boot-starter-web:2.1.1.RELEASE")
}
sirandy
  • 1,834
  • 5
  • 27
  • 32
Siwy
  • 121
  • 1
  • 1
  • 5
  • 1
    Can you post more of your configuration. Because in my case it puts the generated files in the build/class/java/main/ folder. – Rob Anderson Jan 31 '19 at 20:42

5 Answers5

8

You need to provide concrete annotation processor ':jpa'

annotationProcessor("com.querydsl:querydsl-apt:4.2.1:jpa")

that should work:

dependencies{
   annotationProcessor("org.projectlombok:lombok:1.18.4")
   annotationProcessor("com.querydsl:querydsl-apt:4.2.1:jpa")
   annotationProcessor("org.springframework.boot:spring-boot-starter-data-jpa:2.1.1.RELEASE")

   compileOnly("org.projectlombok:lombok:1.18.4")
   implementation("com.querydsl:querydsl-jpa:4.2.1")
   implementation("org.springframework.boot:spring-boot-starter-data-jpa:2.1.1.RELEASE")
   implementation("org.springframework.boot:spring-boot-starter-web:2.1.1.RELEASE")
}
jtomaszk
  • 9,223
  • 2
  • 28
  • 40
  • 1
    annotationProcessor("com.querydsl:querydsl-apt:4.2.1:jpa") is not working for me. Gradle message Annotation processor 'com.querydsl.apt.jpa.JPAAnnotationProcessor' not found. Anything i a missing? Using gradle 5.4 and jdk 8 – TosKen May 14 '19 at 06:52
  • @TosKen checkout my answer, I had the same trouble – TecHunter Oct 14 '19 at 11:25
8

I will give you my working configuration :

ext {
    queryDslVersion = '4.2.1'
    lombokVersion = '1.8.6'
}
// https://stackoverflow.com/questions/42441844/annotation-processor-in-intellij-and-gradle/54611475#54611475
compileJava {
    options.annotationProcessorPath = configurations.annotationProcessor
}

dependencies {
  // ...

    compile(
            "com.querydsl:querydsl-core:${queryDslVersion}",
            "com.querydsl:querydsl-jpa:${queryDslVersion}"
    )

    compileOnly "org.projectlombok:lombok:${lombokVersion}"

    annotationProcessor "com.querydsl:querydsl-apt:${queryDslVersion}:jpa",
            "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
            "javax.annotation:javax.annotation-api:1.3.2",
            "org.projectlombok:lombok:${lombokVersion}"
}

Using Gradle 5.2+

TecHunter
  • 6,091
  • 2
  • 30
  • 47
  • 2
    This works for me in Gradle 5.6 with only `annotationProcessor "com.querydsl:querydsl-apt:4.2.2:jpa", "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final"`. – ach Dec 20 '19 at 15:22
  • @TecHunter this doesn't work for me with `Gradle 5.1`. I am still getting the same error as OP, i.e. `java.lang.IllegalArgumentException: Annotation processor 'com.querydsl.apt.jpa.JPAAnnotationProcessor' not found` – Darshan Mehta Jun 10 '20 at 12:59
  • @DarshanMehta try gradle 5.2+ unless you are restricted with versions – TecHunter Jun 10 '20 at 17:42
  • @TecHunter unfortunately I have to stick to `5.1` due to restrictions – Darshan Mehta Jun 10 '20 at 17:51
  • @DarshanMehta post another SO question with this specificity and reference this post. can't help you sorry – TecHunter Jun 12 '20 at 22:06
  • @TecHunter here you go : https://stackoverflow.com/questions/62320937/gradle-unable-to-generate-querydsl-classes – Darshan Mehta Jun 12 '20 at 22:20
  • this answer worked with Gradle 5.6.4, but not on gradle 6.x versions. – Prabah Nov 06 '20 at 17:48
0

Follow the exact same order

sourceSets {
  generated {
    java {
      srcDirs = ['build/generated/sources/annotationProcessor/java/main']
    }
  }
}


dependencies {
    api 'com.querydsl:querydsl-jpa:4.4.0'
    annotationProcessor 'org.projectlombok:lombok'
    annotationProcessor('com.querydsl:querydsl-apt:4.4.0:jpa')
    annotationProcessor('javax.annotation:javax.annotation-api')

}
Deepak
  • 1,506
  • 1
  • 14
  • 13
0

This works in intellij!!

    ext {
            queryDslVersion = '4.2.1'
            
        }
        
       idea {
          module {
        sourceDirs += file('generated/')
        generatedSourceDirs += file('generated/')
    }
} 
        
        
         dependencies {
                compile("com.querydsl:querydsl-core:${queryDslVersion}")
                compile("com.querydsl:querydsl-jpa:${queryDslVersion}")
            }
            
            dependencies {
            
                compile "com.querydsl:querydsl-jpa:${queryDslVersion}"
                compileOnly 'org.projectlombok:lombok:1.16.18'
                annotationProcessor(
                    "com.querydsl:querydsl-apt:${queryDslVersion}:jpa",
                    "org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
                    "javax.annotation:javax.annotation-api:1.3.2",
                    "org.projectlombok:lombok"
                )

}
Vaishnavi
  • 419
  • 5
  • 9
-1

QueryDSL doesn't work with Gradle 5. You can check this other question and the plug-in issues for more information.

It looks like some people managed to get it to work with workarounds such as the ones in the linked question, but that has not been my case. My team had to resort to using HQL in the end.

Ernani
  • 319
  • 1
  • 4
  • 18
  • It works well (I'm using it with 5.3 right now). `compileQuerydsl { options.annotationProcessorPath = configurations.querydsl }` Please take a look here https://stackoverflow.com/questions/53913274/querydsl-annotation-processor-issue-after-upgrade-to-gradle-5#answer-53930957 – Max Jun 24 '19 at 13:13
  • @Max this isn't working for me, unfortunately... I either have to use HQL or add QueryDSL without the Gradle plugin and create the QClasse manually. What are the configurations of your project? Java version, Spring version... are they the same ones as the question title? – Ernani Jun 24 '19 at 16:47