Thuy's Blog

Remember annotationProcessor?

November 20, 2016

Remember the annotationProcessor scope mentioned in this technical docs? Normally, in order to use some libraries such as immutables and dagger 2, we will have to use a Gradle plugin namely android-apt. So the setup with that plugin goes like:

// Top-level build file where you can add
// configuration options common to all sub-projects/modules.
buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
  }
}

Then, in the build file of a sub-project, we can use the apt scope:

dependencies {
  apt 'org.immutables:value:2.3.7'
  provided 'org.immutables:value:2.3.7:annotations'
  provided 'org.immutables:builder:2.3.7'
  provided 'org.immutables:gson:2.3.7:annotations'

  compile 'com.google.dagger:dagger:2.7'
  apt 'com.google.dagger:dagger-compiler:2.7'
}

That’s it. However that 2-step setup is no longer needed since Gradle plugin v2.2.0 (the stable version was v2.2.2 at the time writing this blogpost). Everything we need is just the built-in annotationProcessor. No third-party plugin is required.

dependencies {
  annotationProcessor 'org.immutables:value:2.3.7'
  provided 'org.immutables:value:2.3.7:annotations'
  provided 'org.immutables:builder:2.3.7'
  provided 'org.immutables:gson:2.3.7:annotations'

  compile 'com.google.dagger:dagger:2.7'
  annotationProcessor 'com.google.dagger:dagger-compiler:2.7'
}

Cool?


Thuy Trinh

Written by Thuy Trinh who lives and works in Frankfurt, Germany building robust Android apps. You should follow him on Twitter