spring-boot, querydsl with gradle

3,000 views
Skip to first unread message

David Clark

unread,
Mar 30, 2014, 10:15:35 AM3/30/14
to quer...@googlegroups.com
I have a limited exposure to QueryDSL and Spring using Maven.  But I am trying to integrate QueryDSL with my gradle 1.7 project and have not been successful.  I have done many online searches, but the various examples do not work for me, so I am hoping someone here can tell me what I am doing wrong.

Here is my build.gradle file, but I get an error that "unsupported Gradle DSL method found: 'querydslapt()":

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'war'

ext {
    querydslVersion = "3.3.1"
}

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC4")
    }
}

jar {
    baseName = 'cnet-ofac-app'
    version = '0.1.0'
}

repositories {
    mavenCentral()
    maven { url: "http://repo.spring.io/libs-snapshot" }
//    maven { url: "http://repo.spring.io/milestone" }

}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.0.0.RC5")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:1.0.0.RC4")
    compile 'org.springframework.data:spring-data-jdbc-core:1.0.0.RELEASE'
    compile("org.springframework:spring-orm:4.0.0.RC1")
    compile("org.hibernate:hibernate-entitymanager:4.2.1.Final")
    compile("com.h2database:h2:1.3.172")
    compile("joda-time:joda-time:2.3")
    compile("org.thymeleaf:thymeleaf-spring4")
    compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
    compile('org.codehaus.groovy:groovy-all:2.2.1')
    compile('org.jadira.usertype:usertype.jodatime:2.0.1')

    compile 'com.mysema.querydsl:querydsl-jpa:3.3.2'

    querydslapt "com.mysema.querydsl:querydsl-apt:$querydslVersion"

    testCompile('org.spockframework:spock-core:0.7-groovy-2.0') {
        exclude group: 'org.codehaus.groovy', module: 'groovy-all'
    }
    testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
    testCompile("junit:junit")
}

jacocoTestReport {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

configurations {
    querydslapt
}

def generatedResources = "$buildDir/generated-resources/main"

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

sourceSets {

    main {
        java {
            srcDirs = []
        }
        groovy {
            srcDirs = ['src/main/groovy', 'src/main/java']
        }
        resources {
            srcDirs = ['src/main/resources']
        }

        output.resourcesDir = "build/classes/main"
        output.dir(generatedResources, builtBy: 'generateQueryDSL')
    }

    test {
        java {
            srcDirs = []
        }
        groovy {
            srcDirs = ['src/test/groovy', 'src/test/java']
        }
        resources {
            srcDirs = ['src/test/resources']
        }

        output.resourcesDir = "build/classes/test"
    }
}


compileJava {
    dependsOn generateQueryDSL
    source generateQueryDSL.destinationDir
}

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

clean {
    delete sourceSets.generated.java.srcDirs
}

idea {
    module {
        sourceDirs += file('src/main/generated')
    }
}

I am really struggling to get this to build and work, so I would be very grateful for any assistance you can offer.



timowest

unread,
Mar 30, 2014, 2:30:24 PM3/30/14
to quer...@googlegroups.com
Hi.

I found this which has been reported to work https://gist.github.com/EdwardBeckett/5377401

I don't use gradle (yet), but maybe try to move configurations before dependencies.

Timo

Ralph Schaer

unread,
Mar 30, 2014, 2:33:39 PM3/30/14
to quer...@googlegroups.com
Hi

I also had problems with spring-boot and querydsl integration at first. Then I noticed that querydsl pulls hibernate-jpa-2.0-api and hibernate pulls hibernate-jpa-2.1-api-1.0.0.Final.jar into the classpath. To resolve the problem I only had to exclude the conflicting jar.

  <dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.3.2</version>
<exclusions>
<exclusion>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<groupId>org.hibernate.javax.persistence</groupId>
</exclusion>
</exclusions>
</dependency> 


One thing I also noticed in your gradle file is that there different versions of spring-boot referenced. I guess this can also lead to problems.

    compile("org.springframework.boot:spring-boot-starter-web:1.0.0.RC5")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:1.0.0.RC4")


Ralph

Timo Westkämper

unread,
Mar 30, 2014, 2:37:09 PM3/30/14
to Querydsl on behalf of Ralph Schaer
Hi,

The hibernate-jpa-2.0-api dependency has provided scope in querydsl-jpa since 3.3.1 https://github.com/mysema/querydsl/blob/master/querydsl-jpa/pom.xml#L64

Br,
Timo


--
You received this message because you are subscribed to the Google Groups "Querydsl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to querydsl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com


Ralph Schaer

unread,
Mar 30, 2014, 2:54:41 PM3/30/14
to quer...@googlegroups.com

Hi

Thanks for the information. The exclude is no longer necessary. I tested it and the jpa 2.0 library is no longer pulled into the classpath.

Ralph

David Clark

unread,
Mar 30, 2014, 7:00:41 PM3/30/14
to quer...@googlegroups.com
Thank you,

I fixed my mismatch spring-boot issue, thank you for noticing that.  But my gradle build fails with:

Could not find method querydslapt() for arguments [com.mysema.querydsl:querydsl-apt:3.3.1]

I believe that is from this section:
configurations {
    querydslapt
}

 and
dependencies {
..
 querydslapt "com.mysema.querydsl:querydsl-apt:$querydslVersion"
}


I saw that on several examples, but I cannot actually find that reference in any documentation.  It looks like part of QueryDSL, but I don't see why its breaking my build.

timowest

unread,
Mar 31, 2014, 4:55:09 AM3/31/14
to quer...@googlegroups.com
Hi.

Gradle is not (yet) officially supported by Querydsl, so the error is probably in the scope of your build script.

Br,
Timo

David Clark

unread,
Mar 31, 2014, 10:23:59 AM3/31/14
to quer...@googlegroups.com
I can't understand why some examples seem to work for others but not for me.  It would seem that some folks have gotten querydsl to work with gradle but I can't tell if that is older versions or not.
Reply all
Reply to author
Forward
0 new messages