3

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.

Community
  • 1
  • 1
Matt James
  • 275
  • 4
  • 13

3 Answers3

4

It is much easier with latest gradle

compileJava {
  options.compilerArgs += [
    '-Aquerydsl.excludedPackages=com.thomsonreuters.domainmodel.eventhistory'
  ]
}

dependencies {
  ...
  compile "com.mysema.querydsl:querydsl-jpa:3.6.3"
  compileOnly "com.mysema.querydsl:querydsl-apt:3.6.3:jpa"
}
MariuszS
  • 30,646
  • 12
  • 114
  • 155
  • I have done configuration as you mentioned but I getting warning as warning: The following options were not recognized by any processor: '[querydsl.excludedPackages]' please refer https://stackoverflow.com/questions/47303776/w-r-t-pass-options-to-jpaannotationprocessor-from-gradle – MasterCode Nov 15 '17 at 09:35
  • 1
    @MasterCode I'm not using gradle anymore (go back to maven), so I cant help. Please vote for this issue: https://github.com/querydsl/querydsl/issues/599 – MariuszS Nov 15 '17 at 12:18
3

I figured out the answer from looking at the source code of the com.mysema.maven:apt-maven-plugin to see how it was passing the extra options.

It takes the values from the options structure, adds the letter A to the beginning of the keys and passes them in the form of key=value. So for the key querydsl.excludedPackages I needed to add something like "-Aquerydsl.excludedPackages=com.package.to.ignore" to the list of options.compilerArgs.

Once I did that I was able to ignore the packages I didn't want processed.

Matt James
  • 275
  • 4
  • 13
2

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
   }

}
Ricardo Veguilla
  • 3,107
  • 1
  • 18
  • 17
  • That's similar to what I am using but I can't figure out how to pass the querydsl.excludedPackages parameter in the options.compilerArgs. In the Maven plugin, the querydsl.execludedPackages was inside a map structure, as shown in the question. – Matt James Sep 18 '14 at 19:57
  • @MattJames, looking at the [QueryDSL apt-maven-plugin source code](https://github.com/querydsl/apt-maven-plugin/blob/master/src/main/java/com/mysema/maven/apt/AbstractProcessorMojo.java), it looks like the option should be passed to annotation processor as `-AoptionaName=optionValue`. I've updated the answer accordingly. – Ricardo Veguilla Sep 18 '14 at 20:31