Deduplicate code in kotlin gradle tasks
Major refactor and code deduplication in KotlinPlugin.kt