4

Does Gradle have an equivalent to the Maven configuration described for the JOOQ type checker annotation processors (https://www.jooq.org/doc/latest/manual/tools/checker-framework/)? The Maven version is:

<dependency>
  <groupId>org.jooq</groupId>
  <artifactId>jooq-checker</artifactId>
  <version>3.10.5</version>
</dependency>

And

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.3</version>
  <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <fork>true</fork>
    <annotationProcessors>
      <annotationProcessor>org.jooq.checker.SQLDialectChecker</annotationProcessor>
    </annotationProcessors>
    <compilerArgs>
      <arg>-Xbootclasspath/p:1.8</arg>
    </compilerArgs>
  </configuration>
</plugin>

However, while I can get the compile dependency into Gradle I'm unsure where to put the annotationProcessor bit. Any help would be greatly appreciated!

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
Gabor Angeli
  • 5,729
  • 1
  • 18
  • 29

1 Answers1

6

Gradle supports annotation processors since Gradle 3.4 by adding a configuration (e. g. named "apt") for the processors and setting the annotationProcessorPath. See CompileOptions#setAnnotationProcessorPath() for details.

Example:

configurations {
    apt
}

dependencies {
    apt 'org.jooq: jooq-checker:3.10.5'
}

tasks.withType(JavaCompile) {
    options.annotationProcessorPath = configurations.apt
    options.compilerArgs << "-processor" << "org.jooq.checker.SQLDialectChecker"
}

Starting with Gradle 4.6 it should even be simpler using the predefined annotationProcessorconfiguration:

dependencies {
    annotationProcessor 'org.jooq: jooq-checker:3.10.5'
}
compileJava.options.compilerArgs << "-processor" << "org.jooq.checker.SQLDialectChecker"

Also take a look at the Gradle 4.6-rc.2 release notes for details. And of course there's always potential for improvement: Make annotation processors a first-class citizen.

And of course there are a few jOOQ plugins for Gradle which you might want to check out: https://plugins.gradle.org/search?term=jooq

joschi
  • 12,746
  • 4
  • 44
  • 50
  • 2
    The officially recommended Gradle plugin is https://github.com/etiennestuder/gradle-jooq-plugin – Lukas Eder Feb 27 '18 at 17:03
  • Do I not have to specify `org.jooq.checker.SQLDialectChecker` anywhere? I've got Gradle to run, but it isn't actually running the JOOQ checker – Gabor Angeli Feb 28 '18 at 00:16
  • @GaborAngeli I've edited the answer to include the necessary steps for specifying the annotation processor explicitly. – joschi Mar 05 '18 at 21:05
  • @LukasEder JOOQ's Gradel plugin does not include or run the checkers, does it? – thee Aug 17 '18 at 21:35
  • @thee: Mind asking a new question, or directly on the plugin's github issue tracker? – Lukas Eder Aug 19 '18 at 10:37
  • Thanks @joschi! I wish the jooq guys would stick this in their documentation along side the maven instructions. – Shadow Man Dec 04 '19 at 21:05