app:transformClassesWithDexBuilderForDebug takes very long time in Android

Whenever I checkout a different branch and build the app, this particular task takes around 10 minutes. It's awfully long.


Android Studio : 3.2.1 Gradle plugin: 3.1.3

I tried many things such as invalidate cache, clean build, clean whole gradle cache etc.

My app contains libraries which uses annotation processor.

Is there any direction to find out the root cause or anyone had a similar issue and solved it?