eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (cat=Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

1. Overview

In this article, we’ll explore the gradle-lint plugin.

First, we’ll see when to use it. Then, we’ll walk through the plugin configuration options. Next, we’ll use some of its predefined rules. Finally, we’ll generate lint reports.

2. What’s Gradle Lint Plugin?

The Gradle Lint plugin helps with linting Gradle configuration files. It enforces build script structure throughout our code base. The plugin can keep the Gradle Wrapper version up to date, prevent bad practices across build files, and remove unused dependencies.

Practically, we use predefined rules or write custom ones. Then, we configure the plugin to consider them as violations or ignore them. The linter runs at the end of most Gradle tasks.

By default, it doesn’t modify the code directly but shows warnings instead. That’s helpful because other Gradle tasks won’t fail due to the plugin. Additionally, those warnings won’t get lost since they are visible at the end of the logs.

Furthermore, gradle-lint provides a fixGradleLint command to auto-fix most lint violations.

Internally, the Gradle Lint Plugin exploits Groovy AST and Gradle Model to apply lint rules. This showcases that the plugin is tightly coupled to the Groovy AST. Because of that, the plugin doesn’t support Kotlin build scripts.

3. Setup

There are three ways to set up the Gradle Lint plugin: in the build.gradle, an initialization script, or a script plugin. Let’s explore each one of them.

3.1. Using build.gradle

Let’s add the gradle-lint plugin to our build.gradle:

plugins {
    id "nebula.lint" version "17.8.0"
}

The plugin should be applied to the root project when using a multi-module project. Since we’ll be using a multi-module project, let’s apply the plugin to the root project:

allprojects {
    apply plugin :"nebula.lint"
    gradleLint {
        rules = [] // we'll add rules here
    }
}

Later on, we’ll add lint rules inside the gradleLint.rules array.

3.2. Using Init Scripts

Apart from build.gradle, we can use init scripts to configure our plugin:

import com.netflix.nebula.lint.plugin.GradleLintPlugin

initscript {
    repositories { mavenCentral() }
    dependencies {
        classpath 'com.netflix.nebula:gradle-lint-plugin:17.8.0'
    }
}

allprojects {
    apply plugin: GradleLintPlugin
    gradleLint {
        rules=[]
    }
}

This lint.gradle script is identical to our setup earlier. To apply it, we’ll pass the –init-script flag to our tasks:

./gradlew build --init-script lint.gradle

An interesting use case is to pass a different init script depending on the environment where the tasks are running. A downside is that we’ll always have to pass the –init-script flag.

3.3. Using Script Plugins

Let’s apply a script plugin directly to our build.gradle:

plugins{
    id "nebula.lint" version "17.8.0"
}
apply from: "gradle-lint-intro.gradle"

The gradle-lint-intro.gradle content will be injected as if it were part of the build script:

allprojects {
    apply plugin: "nebula.lint"
    gradleLint {
        rules= []
    }
}

In this article, we’ll keep our gradle-lint configuration in the build.gradle script.

4. Configuration

Let’s review the different configuration options available in the grade-lint plugin.

4.1. Execution

The command to execute the Gradle Lint plugin is ./gradlew lintGradle. We can call it in isolation or during another task.

By default, the plugin automatically runs at the end of all tasks except these – help, tasks, dependencies, dependencyInsight, components, model, projects, wrapper, and properties:

./gradlew build

This build task ends by calling ./gradlew lintGradle. The linter shows violations as warnings.

Besides, we can prevent the linter from running in a specific task by applying the skipForTask method:

gradleLint {
    skipForTask('build')
}

Here, we prevent the plugin from running during the build task.

In case we want to disable the plugin for all tasks, we can use the alwaysRun flag:

gradleLint {
    alwaysRun = false
}

This is particularly useful when we want to separately call ./gradlew lintGradle at a specific point in time.

It’s important to note that calling the plugin in isolation marks the lint violations as errors, not warnings. 

4.2. Rules Definition

Gradle Lint plugin allows us to configure two groups of rules: violation rules (via rules and critcalRules options) and ignored rules (using excludedRules, ignore, and fixme properties). Let’s explore them.

First, the rules property takes an array of lint rules. When violations defined by the rules are met, the linter raises warnings. But if the Gradle Lint Plugin is running in isolation, those warnings make the build fail.

Next, let’s explore the criticalRules option. We add a rule to the gradleLint.criticalRules property when we want the rule violation to trigger a task failure. The plugin offers a specific criticalLintGradle task to only lint critical rules:

./gradlew criticalLintGradle -PgradleLint.criticalRules=undeclared-dependency

Here, the -PgradleLint.criticalRules option adds the undeclared-dependency rule to criticalRules. Then, the criticalLintGradle task only lints rules defined in criticalRules.

Continuing, the excludedRules option takes a list of rules to ignore. It comes in handy when we want to ignore a specific rule from a group rule:

gradleLint { 
    rules= ['all-dependency']
    excludedRules= ['undeclared-dependency']
 }

We’ve excluded the undeclared-dependency rule from our previous all-dependency group rule. A group rule allows us to apply a set of rules at once.

Finally, we can prevent the linter from scanning parts of our build files by wrapping them in the ignore property:

dependencies {
    testImplementation('junit:junit:4.13.1')
    gradleLint.ignore('dependency-parentheses') {
        implementation("software.amazon.awssdk:sts")
    }
}

We’ve intentionally guarded aws-sts against the dependency-parenthesis rule. It won’t be listed when we run the linter:

warning   dependency-parentheses             parentheses are unnecessary for dependencies
gradle-lint-intro/build.gradle:11
testImplementation('junit:junit:4.13.1')

The dependency-parentheses warns against the unnecessary use of parentheses in the Gradle dependencies declaration.

Besides, we can swap the ignore for the fixme property if we want to temporarily ignore a rule:

gradleLint.fixme('2029-04-23', 'dependency-parentheses') {
    implementation('software.amazon.awssdk:sts')
}

Here, the aws-sts dependency will trigger an unused-dependency violation after April, the 23rd 2029.

It’s important to note that the ignore and fixme properties are only effective on resolved dependencies. They don’t work on wrapped declarations in a build file:

dependencies {
    gradleLint.ignore('unused-dependency') {
        implementation "software.amazon.awssdk:sts"
    }
}

We’ve intentionally guarded aws-sts against the unused dependency rule. We don’t use it directly in our code. But for some reason, it’s required by AWS WebIdentityTokenCredentialsProvider. Unfortunately, the linter won’t catch that because it doesn’t evaluate unresolved dependencies.

4.3. Overriding Configuration Properties

Gradle Lint allows us to override some configuration properties in the command line. We do this by using the -PgradleLint option followed by any valid file configuration option.

Let’s add the unused-dependency rule to our initial empty rules array:

gradleLint { 
    rules= ['unused-dependency'] 
}

Next, let’s prevent the linter from applying it by excluding it via the command line:

./gradlew lintGradle -PgradleLint.excludedRules=unused-dependency

This is the equivalent of setting excludedRules=[“unused-dependency”] in the configuration file.

We can use this pattern for all the other properties, especially when running in CI environments. Multiple values should be comma-separated.

5. Built-in Rules

The Gradle Lint plugin has several built-in lint rules. Let’s explore some of them.

5.1. Minimum Dependency Version Rule

First, let’s see the minimum-dependency-version rule. It shows violations for dependencies that have a strictly lower version than a predefined one:

gradleLint { 
    rules= ['minimum-dependency-version'] 
}

We’ll need to provide the comma-separated list of minimum dependency versions in the minVersions property. But, as of this writing, the GradleLintExtension doesn’t have the minVersions property. Therefore, let’s set it via the command line:

./gradlew lintGradle -PgradleLint.minVersions=junit:junit:5.0.0

Here, the linter warns against the use of junit versions lower than 5.0.0:

> Task :lintGradle FAILED

This project contains lint violations. A complete listing of the violations follows.
Because none were serious, the build's overall status was unaffected.

warning   minimum-dependency-version         junit:junit is below the minimum version of 5.0.0 (no auto-fix available). See https://github.com/nebula-plugins/gradle-lint-plugin/wiki/Minimum-Dependency-Version-Rule for more details

? 1 problem (0 errors, 1 warning)

To apply fixes automatically, run fixGradleLint, review, and commit the changes.

Running ./gradlew fixGradleLint effectively updates junit versions to 5.0.0.

5.2. Undeclared Dependency Rule

Next, we’ll learn about the undeclared-dependency rule. It ensures we have explicitly declared transitive dependencies that we directly use in our code:

gradleLint { 
    rules= ['undeclared-dependency'] 
}

Now, let’s execute the lintGradle task:

> Task :lintGradle FAILED

This project contains lint violations. A complete listing of the violations follows. 
Because none were serious, the build's overall status was unaffected.

warning   undeclared-dependency              one or more classes in org.hamcrest:hamcrest-core:1.3 are required by your code directly

warning   undeclared-dependency              one or more classes in org.apache.httpcomponents:httpcore:4.4.13 are required by your code directly

? 2 problems (0 errors, 2 warnings)

To apply fixes automatically, run fixGradleLint, review, and commit the changes.

We can see that we have two dependencies directly required by our code. The linter adds them after we run the fixlintGradle task:

> Task :fixLintGradle

This project contains lint violations. A complete listing of my attempt to fix them follows. Please review and commit the changes.

fixed          undeclared-dependency              one or more classes in org.hamcrest:hamcrest-core:1.3 are required by your code directly

fixed          undeclared-dependency              one or more classes in org.apache.httpcomponents:httpcore:4.4.13 are required by your code directly

Corrected 2 lint problems

Besides, as of this writing, it’s impossible to feed custom rules to the plugin. An alternative could be to fork the library and add custom rules directly.

Finally, we should be careful when using outdated rules. The archaic-wrapper rule was removed in 2018. Some sections of the documentation are yet to be updated.

6. Generating Reports

Now, let’s generate reports using the generateGradleLintReport task:

./gradlew generateGradleLintReport

By default, the report format is HTML. The plugin places all report files in the build/reports/gradleLint folder. Our HTML report will be named gradle-5.html, where gradle-5 is our root project name.

The other available options are xml and text:

gradleLint {
    reportFormat = 'text'
    reportOnlyFixableViolations = true
}

We’ve used the reportFormat property to directly output the report in plain text. Additionally, our report only contains fixable violations thanks to the activated reportOnlyFixableViolations flag.

7. Conclusion

In this article, we explored the gradle-lint plugin. First, we saw its utility. Then, we listed the different configuration options. Next, we used some predefined rules. Finally, we generated lint reports.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Summer Sale 2026 – NPI EA (cat= Baeldung)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Course – Summer Sale 2026 – NPI (All)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

eBook Jackson – NPI EA – 3 (cat = Jackson)