Generating JPA2 Metamodel from a Gradle build script

前端 未结 7 1389
长情又很酷
长情又很酷 2020-11-30 02:24

I\'m trying to set up a Gradle build script for a new project. That project will use JPA 2 along with Querydsl.

On the following page of Querydsl\'s reference docume

相关标签:
7条回答
  • 2020-11-30 03:26

    While I have no problem with the use gradle makes of Ant, I agree with the original poster that it is undesirable in this case. I found a github project by Tom Anderson here that describes what I believe is a better approach. I modified it a small amount to fit my needs (output to src/main/generated) so that it looks like:

    sourceSets {
         generated
    }
    
    sourceSets.generated.java.srcDirs = ['src/main/generated']
    
    configurations {
         querydslapt
    }
    
    dependencies {     
        compile 'mine go here'
        querydslapt 'com.mysema.querydsl:querydsl-apt:2.7.1'
    }
    
    task generateQueryDSL(type: Compile, 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()
    }
    compileJava.dependsOn generateQueryDSL
    

    This approach makes a lot more sense to me than the other, if it does to you too, then you have another option for querydsl generation.

    0 讨论(0)
提交回复
热议问题