Skip to content

Commit 2bf4968

Browse files
committed
Android: Add failOnWarnings check to android build.gradle and configure lint as warnings as error
1 parent 25199e9 commit 2bf4968

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

android/build.gradle

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ android {
2020
versionName "1.0"
2121
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2222
}
23-
lintOptions { abortOnError true }
23+
24+
//fail on android lint warnings if failOnWarning is set true
25+
lintOptions {
26+
abortOnError true
27+
if (rootProject.hasProperty("failOnWarnings") && rootProject.failOnWarnings.toBoolean()) {
28+
warningsAsErrors true
29+
}
30+
}
31+
2432
publishing {
2533
singleVariant('release') {
2634
withSourcesJar()
@@ -44,6 +52,14 @@ dependencies {
4452
testImplementation libraries.truth
4553
}
4654

55+
//Enforce -Werror on java compiler if failOnWarning is set
56+
tasks.withType(JavaCompile).configureEach {
57+
it.options.compilerArgs += ["-Xlint:all"]
58+
if (rootProject.hasProperty("failOnWarnings") && rootProject.failOnWarnings.toBoolean()) {
59+
it.options.compilerArgs += ["-Werror"]
60+
}
61+
}
62+
4763
tasks.register("javadocs", Javadoc) {
4864
source = android.sourceSets.main.java.srcDirs
4965
classpath += files(android.getBootClasspath())

0 commit comments

Comments
 (0)