Skip to content

Using Lint

Jon Schneider edited this page Sep 5, 2016 · 19 revisions

Configuring

To apply this plugin:

plugins {
  id 'nebula.lint' version '5.1.0'
}

Alternatively:

buildscript {
  repositories { jcenter() }
  dependencies {
    classpath 'com.netflix.nebula:gradle-lint-plugin:latest.release'
  }
}

apply plugin: 'nebula.lint'

Define which rules you would like to lint against:

gradleLint.rules = ['all-dependency'] // add as many rules here as you'd like

For an enterprise build, we recommend defining the lint rules in a init.gradle script or in a gradle script that is included via the Gradle apply from mechanism.

For multimodule projects, we recommend applying the plugin in an allprojects block:

allprojects {
  apply plugin: 'nebula.lint'
  gradleLint.rules = ['all-dependency'] // add as many rules here as you'd like
}

Running

When nebula.lint is applied, build scripts will be automatically linted by a task called lintGradle after the last task in the task graph executes. Results are reported in the console (with ANSI coloring when the console is a TTY).

gradle-lint output

So as not to interfere with common informational tasks, linting does not run if the only tasks in the task graph are 'dependencies', 'dependencyInsight', 'help', 'components', 'projects', 'model', or 'properties'.

For multi-project builds, the lint task will only run once, and will examine every subproject plus the root project.

Auto-fixing violations

Run ./gradlew fixGradleLint (or ./gradlew fixLintGradle, which is an alias) to automatically fix your build scripts! The auto-fix process lists all violations and how they were fixed (when a fix was possible):

gradle-lint output

Generating a lint report

Run ./gradlew generateGradleLintReport to generate a separate report. By default, this task is configured to generate an HTML report. You can change the default by setting:

gradleLint.reportFormat = 'xml' // or 'text' or the default of 'html'