Skip to content

Instantly share code, notes, and snippets.

@iniyanmurugavel
Last active June 12, 2020 12:20
Show Gist options
  • Select an option

  • Save iniyanmurugavel/9d13db6feb7745e252f88c8b97bb09b1 to your computer and use it in GitHub Desktop.

Select an option

Save iniyanmurugavel/9d13db6feb7745e252f88c8b97bb09b1 to your computer and use it in GitHub Desktop.
Kotlin Kapt incremental and Java enableSeperateAnnoatingProcessing
Gradle.properties to improve incremental in kapt annoation processing
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Use incremental annoation Processing instead
#When you include this flag, the Android Gradle plugin executes the annotation processors in a separate task and allows the Java compilation task to run incrementally.
android.enableSeperateAnnoationProcessing = true
# Are you using Dagger, Glide, Room? Chances are you can make your project build much faster by enabling incremental annotation processing.
# Annoation Processing are supported in kotlin with the kapt compiler plugin
# steps :-
#Incremental kapt doesn't work out of the box. There are three conditions that need to be met:
#Use Kotlin 1.3.31 or newer
#Enable incremental kapt by adding kapt.incremental.apt=true in your project’s gradle.properties
#Make sure that all annotation processors in the module support incremental kapt. The whole Gradle module will be non-incremental if there is just one non-incremental annotation processor. \
#This also means that you can move code with non-incremental Kotlin annotations to separate modules to speed up builds.
kapt.use.worker.api=true
#./gradlew aDeb -Pkapt.verbose=true
# Build [INFO] Incremental Kapt support is disabled . Processors that are not incremental dagger. internal.codegen.ComponentProcessor
#The impact on build performance can be huge — one of our bigger projects at Avast went down from 3 minutes to 1 minute build time for incremental builds.\
#It’s more noticeable if you have larger Gradle modules or a monolithic single module project.
#Speed Up your Kotlin projects
#Enabled by default
kapt.incremental.apt=true
#If you want to disable
#kapt.incremental.apt=false
# To disable
#kapt.include.compile.classpath=false
#./gradlew assembleDebug --scan
Gradle Properties
We’re in the last stage now. Remember the gotcha we came across while updating our Gradle plugin version? Turns out the newer versions of Gradle reduce the heap size to 512 MB. This is to make sure lower end machines don’t choke up. I am on a 16 gig machine so I can afford to give around 2–3gigs to the Gradle daemon, but your mileage may vary.
Open the gradle.properties file located at the root of your project and add the following line. Remember to select the size according to your requirements and machine specification.
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
While we’re at it, let’s also enable parallel builds and configure on demand in the properties.
Here’s what my final gradle.properties file looks like:
org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true
kapt.incremental.apt=true
org.gradle.parallel - This flag allows Gradle to build modules within a project in parallel instead of sequentially. This is only beneficial in a multi-module project.
org.gradle.configureondemand - This flag configures only the modules needed by the project, instead of building all of them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment