Skip to content

Instantly share code, notes, and snippets.

@TWiStErRob
Created February 9, 2019 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TWiStErRob/82c584ada9de2bd301091c03f4c26dbb to your computer and use it in GitHub Desktop.
Save TWiStErRob/82c584ada9de2bd301091c03f4c26dbb to your computer and use it in GitHub Desktop.
Automatically add `dagger.formatGeneratedSource` if `dagger-compiler` is present in `annotationProcessor` configuration.
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