Skip to content

Instantly share code, notes, and snippets.

@bitsnaps
Last active August 26, 2021 19:56
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 bitsnaps/ed418ec6385aa6f1465e4696f2595a2a to your computer and use it in GitHub Desktop.
Save bitsnaps/ed418ec6385aa6f1465e4696f2595a2a to your computer and use it in GitHub Desktop.
Activate Type Checking and Compile Static for all Groovy classes in Gradle (or Android) project
// We know we can apply type checking and compile static on all groovy classes, the good news you can do this on gradle build, so it'll be applied in every class in your project, this works in android project.
/*/ In gradle project:
apply plugin: 'groovy'
compileGroovy.groovyOptions.configurationScript = file('gradle/config/groovyc.groovy')
// In Android project (app/build.gradle)
androidGroovy {
options {
configure(groovyOptions) {
configurationScript = file("$projectDir/config/groovyc.groovy")
}
}
}*/
// file: $projectDir/config/groovyc.groovy
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
withConfig(configuration) {
ast(CompileStatic)
ast(TypeChecked)
}
// credits to: https://medium.com/@jonashavers/how-to-activate-type-checking-for-all-groovy-classes-57ce785d5028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment