newbie help! why cant i generate the query classes in my gradle project

1,618 views
Skip to first unread message

William Woodman

unread,
Nov 9, 2013, 11:22:49 AM11/9/13
to quer...@googlegroups.com
newbie to querydsl so go gently with me

I have set up gradle project with Spring-data-mongo and i wanted to try the querydsl - but cant git to work

I read some google posts etc and came up with this for the gradle.build file and i use groovy as the programming model in GGTS

gradle.build
---

apply plugin: 'eclipse'
apply plugin: 'groovy'

sourceCompatibility = 1.7
version = '1.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'MongoSpringData', 'Implementation-Version': version
    }
}

//project variables
ext {
    //spring_version = "3.1.4.RELEASE"
    spring_data_version = "1.3.2.RELEASE"
    }

repositories {
    mavenCentral()
}

dependencies {
    //compile ("org.springframework.boot:spring-boot-starter-web:0.5.0.M5")
    compile ("org.springframework.data:spring-data-mongodb:1.2.1.RELEASE")
    compile     "cglib:cglib:2.2"
    compile     "org.slf4j:slf4j-api:1.7.5"
      compile     "org.slf4j:slf4j-simple:1.7.5"
       compile     'org.codehaus.groovy:groovy-all:2.1.6'
       compile     'com.mysema.querydsl:querydsl-core:3.2.4'
       compile     'com.mysema.querydsl:querydsl-mongodb:3.2.4'
       compile     'com.mysema.querydsl:querydsl-apt:3.2.4' 
   testCompile group: 'junit', name: 'junit', version: '4.+'
   testCompile "org.springframework:spring-test:3.1.4.RELEASE"
  
}

//define where the generated output classes will go for queryDSL
sourceSets {
    generated {
       java {
          srcDirs = ['src/main/generated']
       }
    }
}

//define custom configuration for classpath
configurations {querydslapt}


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",
                              "org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor",
                              /*"-s"*/    ]
    destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
}


compileJava {
    dependsOn generateQueryDSL
    source generateQueryDSL.destinationDir
}

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


clean {
    delete sourceSets.generated.java.srcDirs
}


//not sure why i need this ??
task wrapper(type: Wrapper) {
    gradleVersion = '1.8'
}

test {
    systemProperties 'property': 'value'
}

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'
       }
    }
}
----


I then have a simple domain object for mongo like this annotated @Document

Order.groovy
----
import org.springframework.data.mongodb.core.mapping.Document
//import com.google.code.morphia.annotations.Entity

//@PersistenceCapable

@Document
public class Order {

    @Id
    String id

    String order
    String refName
    Date deliveryDate
    @DBRef
    Customer customer
   
    Order() {}

    Order(String order) {
        this.order = order
    }
   
    Order(String order, Date deliveryDate) {
        this.order = order
        this.deliveryDate = deliveryDate
    }


    @Override
    public String toString() {
        return String.format(
                "Order[id=%s, orderName='%s']",
                id, order)
    }

}

------

lastly i have my OrderRepository like this


//extend from type safe predicate enabled interface
public interface OrderRepository extends MongoRepository<Order, String> , QueryDslPredicateExecutor<Order> {

    Order findByOrder(String order)

    //get complete object
    @Query (value= "{'refName' : ?0}")
    Order findByRefName (String ref)

    //do projection get - get order  and refName only
    @Query (value= "{'order' : ?0}", fields="{'order': 1, 'refName' : 1 }")   
    Order findByOrderProjection (String order)
   
   

}
------

when i run the gradle build - dont get any errors - and it generates the src/main/generated directory - but no QOrder class is generated and i cant reference the object till the class is generated


what am i missing here - how do you get the generated classes ?

heres the build output

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts]      :build
[sts]      :compileGeneratedJava
[sts]      :compileGroovy
[sts]      :compileJava
[sts]      :compileGeneratedGroovy
[sts]      :eclipseClasspath
[sts]      :generateQueryDSL
[sts]      :generatedClasses
[sts]      :processGeneratedResources
[sts]      :processResources
[sts] -----------------------------------------------------
:generateQueryDSL UP-TO-DATE
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
:compileGeneratedJava UP-TO-DATE
:compileGeneratedGroovy UP-TO-DATE
:eclipseClasspath
:processGeneratedResources UP-TO-DATE
:generatedClasses UP-TO-DATE

BUILD SUCCESSFUL

Total time: 24.262 secs
[sts] -----------------------------------------------------
[sts] Build finished succesfully!
[sts] Time taken: 0 min, 24 sec
[sts] -----------------------------------------------------

Timo Westkämper

unread,
Nov 9, 2013, 2:01:25 PM11/9/13
to Querydsl on behalf of William Woodman
Hi.

I don't use Gradle (yet), so I can't help. Sorry.

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/groups/opt_out.



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


William Woodman

unread,
Nov 9, 2013, 6:15:04 PM11/9/13
to quer...@googlegroups.com
Timo -

thanks for the reply - but i thought id try and force a generation and wrote a script class like this that  copied to try and manually force the generation - however i cant get this to run as a cant find the Domain.class - and can find it any jar with this class  - i have all the rest including the javax.persistence onces which i added - and added genericExporter


 i cant find this last missing class - any ideas where that is ?



import javax.persistence.Embeddable
import javax.persistence.Embedded
import javax.persistence.MappedSuperclass

import org.springframework.data.annotation.Transient
import org.springframework.data.mongodb.core.mapping.Document

import com.mysema.query.codegen.GenericExporter

void generateQueryDsl () {
    GenericExporter exporter = new GenericExporter()
    //exporter.setKeywords(Keywords.) //no mongo
    exporter.setEntityAnnotation(Document.class)
    exporter.setEmbeddableAnnotation(Embeddable.class)
    exporter.setEmbeddedAnnotation(Embedded.class)
    exporter.setSupertypeAnnotation(MappedSuperclass.class)
    exporter.setSkipAnnotation(Transient.class)
    exporter.setTargetFolder(new File("src/main/generated/java"))
    exporter.export(DomainClass.class.getPackage())
}

//trigger manual code generation for querydsl
generateQueryDsl ()

William Woodman

unread,
Nov 9, 2013, 6:20:23 PM11/9/13
to quer...@googlegroups.com
one other PS as well - i tried changing the apt processor in the compilerArgs like this from MongAnnotationProcessor to QuerydslAnnotationProcessor and added the @QueryEntity annotation to my class and tried again but that doesnt work either and i cant get any classes to be generated -

rather frustrating -




     options.compilerArgs = [ "-proc:only",
                               "-processor",
                              "com.mysema.query.apt.QuerydslAnnotationProcessor" /*"org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor"*/,
                              /*"-s"  */  ]


has any one else managed to get the querydsl to work using gradle ?  - i think i have copied the samples i have seen - so i'm not sure what i am missing


 

On Saturday, November 9, 2013 4:22:49 PM UTC, William Woodman wrote:

William Woodman

unread,
Nov 9, 2013, 6:39:50 PM11/9/13
to quer...@googlegroups.com
ok last post tonight -

the gradle build doesnt generate but i changed the DomainClass (which is couldnt find) to be my own class in this case Order and ran the script again - at first i though nothing hand happended - but when i did a refresh on the folder in the eclipse the file has been generated  -

not sure it works yet - but i have a QOrder class now - but still cant explain why the gradle build bit doesnt generate me one - have to be missing something 


void generateQueryDsl () {
    GenericExporter exporter = new GenericExporter()
    //exporter.setKeywords(Keywords.) //no mongo
    exporter.setEntityAnnotation(Document.class)
    exporter.setEmbeddableAnnotation(Embeddable.class)
    exporter.setEmbeddedAnnotation(Embedded.class)
    exporter.setSupertypeAnnotation(MappedSuperclass.class)
    exporter.setSkipAnnotation(Transient.class)
    exporter.setTargetFolder(new File("src/main/generated"))
    exporter.export(Order.class.getPackage())

}

//trigger manual code generation for querydsl
println "try generating query files"
generateQueryDsl () 

On Saturday, November 9, 2013 4:22:49 PM UTC, William Woodman wrote:

William Woodman

unread,
Nov 11, 2013, 1:50:15 PM11/11/13
to quer...@googlegroups.com
at the moment i'm running in mixed default mode - so i have both java and groovy in same src/main/java file and i'm  trying to use joint compilation

i then set the extra source setlike this


//define where the generated output classes will go for queryDSL
sourceSets {
    generated {
       java {
          srcDirs = ['src/main/generated']
       }
    }
}

I set a new top level attribute : generatedDir as this

ext {
    //spring_version = "3.1.4.RELEASE"
    spring_data_version = "1.3.2.RELEASE"
    //added new line
    generatedDir = sourceSets.generated.java.srcDirs.iterator().next()
}

I then define my task like this - this time extending GroovyCompile as my domain class is groovy class - if i try and print sourceSets.main.java - it only gets me the QueryDslPredicateExecutor java file (the only java file i have) - which is wrong so i force the source to be my Order.groovy file (annotated with @Document and @QueryEntity.  I set the annotation processor (seems to make no difference) and set the -s outputdirectory for the source to go to.  GroovyCompile type forces you to set the destinationDir so i set it as my generated dir again

task generateQueryDSL(type: GroovyCompile,
                      group: 'build',
                      description: 'Generates the QueryDSL query types') {
    //source =  sourceSets.main.java /*-wrong only one file found sourceSets.main.java */
    println ">> running the generateQueryDSL with generatedDir =  $generatedDir"
    source = "C:/Users/802518659/Documents/temp (not backed up)/grails 3.3 workspace/MongoSpringData/src/main/java/com/softwood/Order.groovy"
    println ">> running the generateQueryDSL on ${source.getAsPath()}"

    classpath = configurations.compile + configurations.querydslapt
    //for groovy compiler as list
    // very pinetickey - if theres a space in the javac between the directive and value, needs to be as
    // two list items
    options.compilerArgs = [ "-proc:only", // process annotations only in pass
                               //"-processor", "com.mysema.query.apt.QuerydslAnnotationProcessor", //processor to use
                               "-processor", "org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor", //processor to use
                              /*"com.mysema.query.apt.QuerydslAnnotationProcessor"*/ /*"org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor" , */
                              "-s", "$generatedDir"  //output directory where generated
                             ]
   
    destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
   
    def lopt = options.compilerArgs
    println ">> compiler  options " + lopt
    println ">> with destination as " + destinationDir
    }

output with --info on is as follows - but no generated QOrder.java (or groovy is generated) - not sure where next any ideas

The client will now receive all logging from the daemon (pid: 5324). The daemon log file: C:\Users\802518659\.gradle\daemon\1.5\daemon-5324.out.log
Executing build with daemon context: DefaultDaemonContext[uid=a450b9a0-013e-4f59-aebc-ea0bd9e16fba,javaHome=C:\Program Files (x86)\Java\jdk1.7.0_21,daemonRegistryDir=C:\Users\802518659\.gradle\daemon,pid=5324,idleTimeout=10800000,daemonOpts=-Xms128m,-Xmx256m,-Dfile.encoding=windows-1252]
Closing daemon's stdin at end of input.
The daemon will no longer process any standard input.
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 'C:\Users\802518659\Documents\temp (not backed up)\grails 3.3 workspace\MongoSpringData\build.gradle'.
Included projects: [root project 'MongoSpringData']
Evaluating root project 'MongoSpringData' using build file 'C:\Users\802518659\Documents\temp (not backed up)\grails 3.3 workspace\MongoSpringData\build.gradle'.
>> running the generateQueryDSL with generatedDir =  C:\Users\802518659\Documents\temp (not backed up)\grails 3.3 workspace\MongoSpringData\src\main\generated
>> running the generateQueryDSL on C:\Users\802518659\Documents\temp (not backed up)\grails 3.3 workspace\MongoSpringData\src\main\java\com\softwood\Order.groovy
>> compiler  options [-proc:only, -processor, org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor, -s, C:\Users\802518659\Documents\temp (not backed up)\grails 3.3 workspace\MongoSpringData\src\main\generated]
>> with destination as C:\Users\802518659\Documents\temp (not backed up)\grails 3.3 workspace\MongoSpringData\src\main\generated
All projects evaluated.
:: loading settings :: url = jar:file:/C:/Users/802518659/.gradle/wrapper/dists/gradle-1.5-bin/9si5v6u7tk37kj5dlsrdcm595/gradle-1.5/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
Selected primary tasks ':build', ':compileGeneratedJava', ':compileGroovy', ':compileJava', ':compileGeneratedGroovy', ':eclipseClasspath', ':generateQueryDSL', ':generatedClasses', ':processGeneratedResources', ':processResources'
Tasks to be executed: [task ':generateQueryDSL', task ':compileJava', task ':compileGroovy', task ':processResources', task ':classes', task ':jar', task ':assemble', task ':compileTestJava', task ':compileTestGroovy', task ':processTestResources', task ':testClasses', task ':test', task ':check', task ':build', task ':compileGeneratedJava', task ':compileGeneratedGroovy', task ':eclipseClasspath', task ':processGeneratedResources', task ':generatedClasses']
:generateQueryDSL
Skipping task ':generateQueryDSL' as it is up-to-date.
Skipping task ':generateQueryDSL' as it is up-to-date
:generateQueryDSL UP-TO-DATE
:compileJava
Skipping task ':compileJava' as it is up-to-date.
Skipping task ':compileJava' as it is up-to-date
:compileJava UP-TO-DATE
:compileGroovy
Skipping task ':compileGroovy' as it has no source files.
:compileGroovy UP-TO-DATE
:processResources
Skipping task ':processResources' as it is up-to-date.
Skipping task ':processResources' as it is up-to-date
:processResources UP-TO-DATE
:classes
Skipping task ':classes' as it has no actions.
:classes UP-TO-DATE
:jar
Skipping task ':jar' as it is up-to-date.
Skipping task ':jar' as it is up-to-date
:jar UP-TO-DATE
:assemble
Skipping task ':assemble' as it has no actions.
:assemble UP-TO-DATE
:compileTestJava
Skipping task ':compileTestJava' as it has no source files.
:compileTestJava UP-TO-DATE
:compileTestGroovy
Skipping task ':compileTestGroovy' as it has no source files.
:compileTestGroovy UP-TO-DATE
:processTestResources
Skipping task ':processTestResources' as it is up-to-date.
Skipping task ':processTestResources' as it is up-to-date
:processTestResources UP-TO-DATE
:testClasses
Skipping task ':testClasses' as it has no actions.
:testClasses UP-TO-DATE
:test
file or directory 'C:\Users\802518659\Documents\temp (not backed up)\grails 3.3 workspace\MongoSpringData\build\classes\test', not found
Skipping task ':test' as it is up-to-date.
Skipping task ':test' as it is up-to-date
:test UP-TO-DATE
:check
Skipping task ':check' as it has no actions.
:check UP-TO-DATE
:build
Skipping task ':build' as it has no actions.
:build UP-TO-DATE
:compileGeneratedJava
Skipping task ':compileGeneratedJava' as it has no source files.
:compileGeneratedJava UP-TO-DATE
:compileGeneratedGroovy
Skipping task ':compileGeneratedGroovy' as it has no source files.
:compileGeneratedGroovy UP-TO-DATE
:eclipseClasspath
:processGeneratedResources
Skipping task ':processGeneratedResources' as it has no source files.
:processGeneratedResources UP-TO-DATE
:generatedClasses
Skipping task ':generatedClasses' as it has no actions.
:generatedClasses UP-TO-DATE




On Saturday, November 9, 2013 4:22:49 PM UTC, William Woodman wrote:
Reply all
Reply to author
Forward
0 new messages