nebula-plugins / gradle-lint-plugin

A pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts.
Apache License 2.0
769 stars 88 forks source link

Unused dependencies declared via `dependencies.create` are not detected #363

Open LaurensLeeuwis opened 2 years ago

LaurensLeeuwis commented 2 years ago

When I have an unused dependency declared using dependencies.create, these are not identified by the plugin:

plugins {
    id 'java'
    id 'nebula.lint' version '17.5.0'
}

gradleLint.rules = ['unused-dependency']

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation dependencies.create('org.springframework:spring-core:5.2.18.RELEASE')
}

results in:

$ ./gradlew clean lintGradle 

BUILD SUCCESSFUL in 849ms
3 actionable tasks: 3 executed

while declaring the same dependency using

dependencies {
    implementation 'org.springframework:spring-core:5.2.18.RELEASE'
}

results in:

$ ./gradlew clean lintGradle

> 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   unused-dependency                  this dependency is a service provider unused at compileClasspath time and can be moved to the runtimeOnly configuration (no auto-fix available)
build.gradle:16
implementation 'org.springframework:spring-core:5.2.18.RELEASE'

... etc etc ...

Can dependencies.create be supported?