queryDSL with build.gradle integration

buildship

(Al Grant) #1

I am trying to get my Q Classes for queryDSL 1.4.1 recongised in a Spring-Boot 1.5.2 project. The IDE is Intellij Ultimate.

buildscript {
ext {
	springBootVersion = '1.5.2.RELEASE'
}
repositories {
	mavenCentral()
}
dependencies {
	classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}

}

plugins {
id ‘net.ltgt.apt’ version '0.8’
id ‘java’
}

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

version = '0.0.5-SNAPSHOT’
sourceCompatibility = 1.8

ext {
queryDslVersion = '4.1.4’
javaGeneratedSources = file("$buildDir/generated-sources/java")
}

compileJava {
doFirst {
javaGeneratedSources.mkdirs()
}
options.compilerArgs += [
’-parameters’, ‘-s’, javaGeneratedSources
]
}

idea {
module {
sourceDirs += file(‘generated/’)
generatedSourceDirs += file(‘generated/’)
}
}

repositories {
mavenCentral()
}

dependencies {
compile(‘org.springframework.boot:spring-boot-starter-data-jpa’)
compile(‘org.springframework.boot:spring-boot-starter-jdbc’)
compile(‘org.springframework.boot:spring-boot-starter-thymeleaf’)
compile(‘org.springframework.boot:spring-boot-starter-web’)
compile(‘org.springframework.boot:spring-boot-starter-security’)
compile(‘org.springframework.boot:spring-boot-starter-mail:1.5.7.RELEASE’)
compile (“org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.0.RELEASE”)
compile group: ‘org.springframework.boot’, name: ‘spring-boot-starter-logging’, version: '1.5.2.RELEASE’
compile group: ‘org.thymeleaf.extras’, name: ‘thymeleaf-extras-springsecurity4’, version: '2.1.2.RELEASE’
compile group: ‘org.springframework.boot’, name: ‘spring-boot-autoconfigure’, version: '1.5.2.RELEASE’
compile(“com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.4.0”)

compile group: 'org.hibernate', name: 'hibernate-java8'

compile "com.querydsl:querydsl-root:$queryDslVersion"
compile "com.querydsl:querydsl-jpa:$queryDslVersion"
compileOnly "com.querydsl:querydsl-apt:$queryDslVersion:jpa"

compile("org.springframework.boot:spring-boot-devtools")
compile('mysql:mysql-connector-java')
testCompile('org.hsqldb:hsqldb')
testCompile('org.springframework.boot:spring-boot-starter-test')

}

But I get error when I try to build the project with this config:

\demo3\src\main\java\com\example\services\EpisodeServiceImpl.java:13: error: cannot find symbol
import com.example.domain.QEpisode;
^
symbol: class QEpisode
location: package com.example.domain
1 error

The Q classes are generated at:

build\generated\source\apt\main\generated\com\example\domain
Even though the javaGeneratedSources points to file $buildDir/generated-sources/java (that folder is empty).

What I have so far is based on this https://discuss.gradle.org/t/integrating-spring-boot-querydsl-into-gradle-build/15421 and the SO answers within it.

But I obviously are still having issues.


(Tom Hartwell) #2

We moved to using a plugin that does most of the heavy lifting:

It hasn’t had any updates in the last few months, but it worked like a charm and replaced all of our Query DSL gradle code. It simplified down to

querydsl.gradle

repositories {
    mavenCentral()
}

apply plugin: "com.ewerk.gradle.plugins.querydsl"
apply plugin: 'idea'


sourceCompatibility = 1.8
targetCompatibility = 1.8


querydsl {
    querydslDefault = true
    jpa = true
}

idea {
    module {
        sourceDirs += file('src/querydsl/')
        generatedSourceDirs += file('src/querydsl/')
    }
}

dependencies {
    compile "com.querydsl:querydsl-jpa:$querydslVersion"
}

You may not need the jpa dependency, we did.

project using Query DSL at the bottom of the build.gradle:

apply from: "${rootDir}/querydsl.gradle"

(Karsten Ludwig Hauser) #3

Hi together,

I do have an eclipse problem with this. The compiled Q-classes are put automatically into the ‘bin/querydsl’ folder. But this folder is not used during the test execution in eclipse (NoClassDefFoundException…). If I change the Output folder in the Java Build Path to ‘bin/main’ the test runs through. Does anybody had also this experience or maybe could help?