Running Lint on Java / Kotlin modules

Niklas Baudy
2 min readAug 25, 2018

--

Starting with the Android Gradle Plugin 3.1.0 you can apply Android Lint to Java / Kotlin modules.

Setup

It’s as simple as adding the dependency of the Android Gradle Plugin and applying the Lint Plugin.

buildscript {
repositories {
google()
}
dependencies {
classpath "com.android.tools.build:gradle:3.1.0"
}
}
apply plugin: "java-library"
apply plugin: "com.android.lint"

Configuration

Configuring Lint can be done with the lintOptions DSL.

lintOptions {
abortOnError true
warningsAsErrors true
// Many many more.
}

You can look up all of the possible configurations here. The same configuration can also be used inside android modules with the android {} block.

Supported Lint issues

The number of supported built-in Lint checks is much lower though since not every Lint check that targets Android is also applicable to non-android projects.

For example, one check that is supported is GradleDependency. It checks if a newer version of your dependency is available. A report after running ./gradlew lint can look like this:

Versioning

3.1.0 is super old. It’s best to use the 3.2.0 version which is currently 3.2.0-rc02. They have fixed a lot of things there. If you’re even more adventurous and you should be, use 3.3.0-alpha07. There you get all of the latest goodies.

Conclusion

It’s nice that we can use Lint for Java / Kotlin modules. It does already provide great benefit however there are still a few things to improve:

Mainly, I think this is because not that many people know that Lint can be used on Java and Kotlin modules. In case you find anything you can report it on their issue tracker.

If you want a sample project where the Lint Plugin is applied be sure to check mine out.

--

--