How to add -Xlint:unchecked to my Android Gradle based project? How to add -Xlint:unchecked to my Android Gradle based project? android android

How to add -Xlint:unchecked to my Android Gradle based project?


This is what worked for me:(in your project's build.gradle)

allprojects {    gradle.projectsEvaluated {        tasks.withType(JavaCompile) {            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"        }    }}


Disclaimer: Even though this answer has more than 10 upvotes, it does not address the problem in the context of an Android project. However, Google finds this question in the context of non-Android projects. Thus, I keep this answer for those folks.

According to JavaCompile, the following seems to be solution:

compileJava {    options.encoding = 'UTF-8'    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"}

If you want it to have for the test cases, use compileTestJava

compileTestJava {    options.encoding = 'UTF-8'    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"}


For everyone using gradle.kts use the following to match up with the simple build.gradle file

build.gradle.kts

afterEvaluate {        tasks.withType(JavaCompile::class) {            options.compilerArgs.add("-Xlint:unchecked")            options.compilerArgs.add("-Xlint:deprecation")        }    }

build.gradle

 gradle.projectsEvaluated {        tasks.withType(JavaCompile) {            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"        }    }