Вопрос

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?

Это было полезно?

Решение

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.

Другие советы

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top