IntelliJ 15 with QueryDSL and Gradle

I have a Spring-boot 1.4 project in IntelliJ 15 using gradle 2.3 and QueryDSL 4.1.3 that will not be built because my objects are not embedded in Querydsl Q classes. I have the following:

buildscript { ext { springBootVersion = '1.4.0.BUILD-SNAPSHOT' querydslVersion = '4.1.3' } repositories { mavenCentral() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } maven {url "https://plugins.gradle.org/m2/"} } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath "gradle.plugin.com.ewerk.gradle.plugins:querydsl-plugin:1.0.7" } } apply plugin: 'java' apply plugin: 'idea' apply plugin: 'eclipse' apply plugin: 'spring-boot' apply plugin: 'jacoco' apply plugin: 'groovy' apply plugin: "com.ewerk.gradle.plugins.querydsl" jar { baseName = 'billing' version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() jcenter() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } maven { url "https://repo.spring.io/libs-snapshot" } maven { url "https://repo.spring.io/libs-snapshot"} maven {url "https://plugins.gradle.org/m2/"} } dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-security') compile('org.springframework.boot:spring-boot-starter-web') compile "com.querydsl:querydsl-root:$querydslVersion" compile "com.querydsl:querydsl-jpa:$querydslVersion" compile "com.querydsl:querydsl-apt:$querydslVersion:jpa" compile 'org.codehaus.groovy:groovy-all:2.4.1' compile fileTree(dir: "libs/qbo-sdk-2.5.0", include: "*.jar") testCompile('org.springframework.boot:spring-boot-starter-test') testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { exclude group: 'org.codehaus.groovy', module: 'groovy-all' } testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude group: 'org.spockframework', module: 'spock-core' } testCompile("junit:junit") } sourceSets { main { output.resourcesDir = output.classesDir } generated { java { srcDirs = ['src/main/generated'] } } } querydsl { library = 'com.mysema.querydsl:querydsl-apt' querydslDefault = true } test { reports.junitXml.destination = file('build/test-results/folder') } jacoco { toolVersion = "0.7.0.201403182114" } jacocoTestReport { group = "Reporting" description = "Generate Jacoco coverage reports after running tests." } configurations { querydslapt } task wrapper(type: Wrapper) { gradleVersion = '2.3' } idea { module { sourceDirs += file('generated/') generatedSourceDirs += file('generated/') } } 

when I run my unit tests, I get an error:

 Caused by: java.lang.ClassNotFoundException: com.company.billing.customer.QCustomer 

And when I run "gradle clean build", I get: Could not find com.mysema.querydsl: querydsl-apt :.

Search in the following places: https://repo1.maven.org/maven2/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https://repo1.maven.org/maven2/com/mysema/ querydsl / querydsl-apt // querydsl-apt-.jar https://jcenter.bintray.com/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https://jcenter.bintray.com/ com / mysema / querydsl / querydsl-apt // querydsl-apt-.jar https://repo.spring.io/snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.pom https: // repo.spring.io/snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar https://repo.spring.io/milestone/com/mysema/querydsl/querydsl-apt//querydsl- apt-.pom https://repo.spring.io/milestone/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar https://repo.spring.io/libs-snapshot/com/mysema /querydsl/querydsl-apt//querydsl-apt-.pom https://repo.spring.io/libs-snapshot/com/mysema/querydsl/querydsl-apt//querydsl-apt-.jar

I understand that QueryDsl was refactoring packages between 3 and 4, but it looks like my dependencies cannot be found, although they are clearly here: <a10>

At least this is my current theory about why my build fails. Has anyone gotten the latest spring, gradle and querydsl to work?

Update : I uninstalled the ewerk plugin and simplified the build.gradle file, so now everything is built correctly. I am updating to help everyone who might need it:

 buildscript { ext { springBootVersion = '1.4.0.BUILD-SNAPSHOT' querydslVersion = '4.1.3' } repositories { mavenCentral() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'idea' apply plugin: 'eclipse' apply plugin: 'spring-boot' apply plugin: 'jacoco' apply plugin: 'groovy' jar { baseName = 'billing' version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() jcenter() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } maven { url "https://repo.spring.io/libs-snapshot" } maven { url "https://repo.spring.io/libs-snapshot"} maven {url "https://plugins.gradle.org/m2/"} } dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-security') compile('org.springframework.boot:spring-boot-starter-web') compile "com.querydsl:querydsl-root:$querydslVersion" compile "com.querydsl:querydsl-jpa:$querydslVersion" compile "com.querydsl:querydsl-apt:$querydslVersion:jpa" compile 'org.codehaus.groovy:groovy-all:2.4.1' compile fileTree(dir: "libs/qbo-sdk-2.5.0", include: "*.jar") testCompile('org.springframework.boot:spring-boot-starter-test') testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { exclude group: 'org.codehaus.groovy', module: 'groovy-all' } testCompile('org.spockframework:spock-spring:1.0-groovy-2.4') { exclude group: 'org.spockframework', module: 'spock-core' } testCompile("junit:junit") } test { reports.junitXml.destination = file('build/test-results/folder') } jacoco { toolVersion = "0.7.0.201403182114" } jacocoTestReport { group = "Reporting" description = "Generate Jacoco coverage reports after running tests." } task wrapper(type: Wrapper) { gradleVersion = '2.3' } idea { module { sourceDirs += file('generated/') generatedSourceDirs += file('generated/') } } 
+5
source share
2 answers

Do you see your QClasses generated in Gradle output? From your mistake, it seems that she has already passed the point where she should generate them.

I think the problem is that you are not setting up a JPAAnnotationProcessor . This is done as a convenience in Gradle by adding: jpa to your querydsl-apt dependency. In Maven, you apply the plugin manually .

I have the following in my build.gradle related to querydsl.

 idea { module { sourceDirs += file('generated/') generatedSourceDirs += file('generated/') } } [...] compile "com.querydsl:querydsl-root:$querydslVersion" compile "com.querydsl:querydsl-jpa:$querydslVersion" compile "com.querydsl:querydsl-apt:$querydslVersion:jpa 

The idea block just auto-configures the generated source directory in IDEA, so the assemblies inside the IDE work correctly.

EDIT:

The output of JPAAnnotationProcessor as follows.

 Note: Running JPAAnnotationProcessor Note: Serializing Supertypes Note: Generating com.myclass.example.QMappedSuperClass for [com.myclass.example.MappedSuperClass] Note: Serializing Entity types Note: Generating com.myclass.example.QMyClass for [com.myclass.example.MyClass] 

EDIT:

I was not familiar with the ewerk plugin, so I looked. It looks like it is trying to activate the JPAAnnotationProcessor for you. You may need to set the JPA flag for documentation here , since the default is false.

See comment for dependency issues.

+7
source

If someone wants to do this with Kotlin and Gradle kotlin dsl here, how do you do this with this setting:

build.gradle.kts

 plugins { [...] id("org.jetbrains.kotlin.kapt") version kotlinVersion } dependencies { [...] compile("com.querydsl:querydsl-core:$queryDslVersion") compile("com.querydsl:querydsl-jpa:$queryDslVersion") kapt("com.querydsl:querydsl-apt:$queryDslVersion:jpa") } 

Note. You may need to use Java 8 for Gradle until the Kapt error is fixed in Kotlin 1.2.20.

0
source

All Articles