Search code examples
jpagradlequerydsl

Pass options to JPAAnnotationProcessor from Gradle


I have a Gradle task that uses the Querydsl JPAAnnotationProcessor to generate JPA query type source files from annotations. I am using a Gradle task very similar to the one in the response by joeG in the post Generating JPA2 Metamodel from a Gradle build script.

I am able to generate the source files, but I would like to exclude some files in a certain package. The Querydsl documentation lists the querydsl.excludedPackages option. How can I pass this option to the JPAAnnotationProcessor in Gradle?

In Maven I can use the apt-maven-plugin and in the configuration pass something like:

<options>
<querydsl.excludedPackages>com.thomsonreuters.domainmodel.eventhistory</querydsl.excludedPackages>
</options>

But I can not figure out how to do this using Gradle.


Solution

  • I currently used this build.gradle script to generate QueryDSL types:

    project("my-project") {
    
       sourceSets {
           generated {
               java {
                   srcDir 'src/main/generated'
               }
           }
       }
    
       configurations {
          querydslapt
       }
    
       dependencies {      
          // your dependencies
          querydslapt  "com.mysema.querydsl:querydsl-apt:3.4.0"
       }
    
       task generateSources(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', 
                                   '-Aquerydsl.excludedPackages=com.thomsonreuters.domainmodel.eventhistory']
           options.warnings = false
           destinationDir = file('src/main/generated')
           outputs.dir destinationDir
       }
    
       compileJava.source generateSources.outputs.files
    
       clean {
           delete sourceSets.generated.java.srcDirs
       }
    
    }