Created
February 9, 2019 00:43
-
-
Save TWiStErRob/82c584ada9de2bd301091c03f4c26dbb to your computer and use it in GitHub Desktop.
Automatically add `dagger.formatGeneratedSource` if `dagger-compiler` is present in `annotationProcessor` configuration.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
allProjects { project -> | |
tasks.withType(JavaCompile).configureEach { JavaCompile task -> | |
task.doFirst { | |
// annotationProcessorPath is populated around afterEvaluate, but can't use that in configureEach | |
if (hasDagger(task.options.annotationProcessorPath)) { | |
task.options.compilerArgs += [ | |
// disable formatting, why wait if it looks almost the same?! | |
'-Adagger.formatGeneratedSource=disabled' | |
] | |
} | |
} | |
} | |
} | |
static def hasDagger(FileCollection files) { | |
if (files instanceof Configuration) { | |
def config = files as Configuration | |
return config.allDependencies | |
.any { it.group == 'com.google.dagger' && it.name == 'dagger-compiler' } | |
} else { | |
return files.files | |
.any { it.name.matches(/dagger-compiler-.*\.jar/) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment