Siwy
Siwy

Reputation: 121

Java 11 + QueryDSL 4 + Gradle 5 + SpringBoot 2.1- not generating QClasses

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")
}

Upvotes: 12

Views: 12511

Answers (5)

Vaishnavi
Vaishnavi

Reputation: 449

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"
                )

}

Upvotes: 0

Deepak
Deepak

Reputation: 1716

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')

}

Upvotes: 0

TecHunter
TecHunter

Reputation: 6141

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+

Upvotes: 8

Ernani
Ernani

Reputation: 339

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.

Upvotes: -1

jtomaszk
jtomaszk

Reputation: 11201

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")
}

Upvotes: 8

Related Questions