4

I'm trying to use QDataTableRepository in my project. It makes me must import querydsl.

build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'idea'

repositories {
    mavenCentral()
}


dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.postgresql:postgresql:9.4.1212')
    compile('org.projectlombok:lombok:1.16.10')
    compile group: 'com.github.darrachequesne', name: 'spring-data-jpa-datatables', version: '3.1'
    compile group: 'com.querydsl', name: 'querydsl-jpa', version: '4.1.4'
    compile group: 'com.querydsl', name: 'querydsl-apt', version: '4.1.4'

    testCompile('org.springframework.boot:spring-boot-starter-test')

}

configurations {
    querydslapt
}

sourceSets {
    generated
}
sourceSets.generated.java.srcDirs = ['generated/']

task generateQueryDSL(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
    source = sourceSets.main.java
    classpath = configurations.compile + configurations.querydslapt
    options.compilerArgs = [
            "-proc:only",
            "-processor", "com.mysema.query.apt.jpa.JPAAnnotationProcessor"
    ]
    destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}

compileGeneratedJava {
    dependsOn generateQueryDSL
    classpath += sourceSets.main.runtimeClasspath
}

And I also setting Annotation Processor in Intellij.

Picture of Annotation Processor setting

I build my project and build successful. The QClass generate inside.
Here

Structure

/**
 * QClient is a Querydsl query type for Client
 */
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QClient extends EntityPathBase<Client> {

But when I run the project the error .

Caused by: java.lang.IllegalArgumentException: Did not find a query class com.project.module.client.QClient for domain class om.project.module.client.Client!

Did I missing the configuration?

limrain
  • 51
  • 1
  • 5
  • Possible duplicate of [QueryDSL, spring-boot & Gradle](https://stackoverflow.com/questions/22773639/querydsl-spring-boot-gradle) – asm0dey Jan 27 '18 at 08:00

1 Answers1

0

For all those that still have this issue - like I do from time to time:

By default the Q-Classes are generated in the target/generated-sources/annotations folder in my case. This folder also gets automatically marked as a sources folder (File -> Project Structure -> Modules -> Sources):

enter image description here

What helped me:

Remove this source folder and select the following as source folder: target/generated-sources/annotations/com

enter image description here

Click Apply -> OK and run the project.

See this answer for a Gradle-based solution.

Petar Bivolarski
  • 1,599
  • 10
  • 19