QueryDSL for Mongo with Spring and gradle

我的梦境 提交于 2019-12-11 00:31:16

问题


How do I generate the predicate classes (Q* classes) with gradle? I want to use Q* classes for Mongo using Spring data. Spring documentation shows maven and ant versions but no gradle.

Is there any plugin out there that I could use?


回答1:


You can use the same approach is presented here Generating JPA2 Metamodel from a Gradle build script

Just replace the Querydsl JPA APT processor with the Spring Mongodb processor.




回答2:


There is an example in my project: spring-data-demo

You will need to define the relevant source to scan. In this case it is: 'org/springframework/data/demo/data/**' queryDslVersion is defined in gradle.properties

configurations {
    queryDslTool
}

dependencies {
    queryDslTool group: 'com.mysema.querydsl', name: 'querydsl-apt', version: queryDslVersion
}

task generateSources {
    def queryDslDir = new File(buildDir, 'generated-sources/java')
    sourceSets.main.java.srcDirs += queryDslDir
    inputs.files(sourceSets.main.java.srcDirs)
    outputs.dir(queryDslDir)
    doLast {
        if (!queryDslDir.exists()) {
            queryDslDir.mkdirs()
        }
        def classPathStr = (configurations.queryDslTool + sourceSets.main.runtimeClasspath).asPath
        ant {
            javac(classpath: classPathStr, includes: 'org/springframework/data/demo/data/**', includeantruntime: false) {
                sourceSets.main.java.srcDirs.each {
                    if (it != queryDslDir) {
                        src(path: it.path)
                    }
                }
                compilerarg value: '-proc:only'
                compilerarg value: '-processor'
                compilerarg value: 'com.mysema.query.apt.QuerydslAnnotationProcessor'
                compilerarg value: '-s'
                compilerarg value: queryDslDir.path
            }
            echo(message: 'Generated QueryDSL Helpers')
        }
    }
}

compileJava.dependsOn generateSources


来源:https://stackoverflow.com/questions/22564178/querydsl-for-mongo-with-spring-and-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!