Repository: ben-manes/gradle-versions-plugin (kotlin)

Issue:
Enhancement request to exclude configurations from check
Certain plugins create their own configurations for resolution, and these configurations are picked up by the plugin and merged into the report.  It causes some level of confusion in many circumstances when reading the reports.

For example, spotbugs plugin generates several configurations (Spotbugs, SpotbugsPlugins, SpotbugsSlf4j), which cause weirdness like duplicate entries for slf4j, entries for unknown libraries that are not directly configured, etc.  Similar things happen with com.diffplug.spotless, and other similar plugins.  

It would be good if it was possible to either specify the specific configurations to resolve, or specify configurations to exclude when executing the plugin.

Pull request description:
Closes #782

This needs someone with actual knowledge of kotlin/groovy to look at it, but the logic itself and the test is written.

Patch:
diff --git a/README.md b/README.md
index 006394d95..ec1dbe5db 100644
--- a/README.md
+++ b/README.md
@@ -307,6 +307,19 @@ tasks.named<DependencyUpdatesTask>("dependencyUpdates").configure {
 
 Note: Do use the `plugins { .. }` syntax if you use the Kotlin DSL.
 
+#### Configuration filter
+You can change which dependency configurations the plugin checks for updates like this:
+
+```groovy
+// https://github.com/ben-manes/gradle-versions-plugin
+tasks.named("dependencyUpdates").configure {
+  filterConfigurations {
+    it.name.equals("runtimeClasspath") || it.name.equals("compileClasspath")
+  }
+}
+```
+
+
 #### Try out the samples
 
 Have a look at [`examples/groovy`](https://github.com/ben-manes/gradle-versions-plugin/tree/master/examples/groovy) and [`examples/kotlin`](https://github.com/ben-manes/gradle-versions-plugin/tree/master/examples/kotlin)
diff --git a/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdates.kt b/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdates.kt
index 185030f94..093575a22 100644
--- a/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdates.kt
+++ b/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdates.kt
@@ -6,6 +6,7 @@ import org.gradle.api.Action
 import org.gradle.api.Project
 import org.gradle.api.artifacts.Configuration
 import org.gradle.api.artifacts.UnresolvedDependency
+import org.gradle.api.specs.Spec
 
 /**
  * An evaluator for reporting of which dependencies have later versions.
@@ -28,6 +29,7 @@ class DependencyUpdates @JvmOverloads constructor(
   val gradleReleaseChannel: String,
   val checkConstraints: Boolean = false,
   val checkBuildEnvironmentConstraints: Boolean = false,
+  val filterConfigurations: Spec<Configuration> = Spec<Configuration> { true }
 ) {
 
   /**
@@ -36,7 +38,8 @@ class DependencyUpdates @JvmOverloads constructor(
    */
   fun run(): DependencyUpdatesReporter {
     val projectConfigs = project.allprojects
-      .associateBy({ it }, { it.configurations.toLinkedHashSet() })
+      .associateBy({ it }, { it.configurations.matching(filterConfigurations).toLinkedHashSet() })
+
     val status: Set<DependencyStatus> = resolveProjects(projectConfigs, checkConstraints)
 
     val buildscriptProjectConfigs = project.allprojects


Test patch:
diff --git a/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdatesTask.kt b/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdatesTask.kt
index 90f7ed070..aafa56f1b 100644
--- a/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdatesTask.kt
+++ b/gradle-versions-plugin/src/main/kotlin/com/github/benmanes/gradle/versions/updates/DependencyUpdatesTask.kt
@@ -9,6 +9,8 @@ import com.github.benmanes.gradle.versions.updates.resolutionstrategy.Resolution
 import groovy.lang.Closure
 import org.gradle.api.Action
 import org.gradle.api.DefaultTask
+import org.gradle.api.artifacts.Configuration
+import org.gradle.api.specs.Spec
 import org.gradle.api.tasks.Input
 import org.gradle.api.tasks.Internal
 import org.gradle.api.tasks.Optional
@@ -93,6 +95,9 @@ open class DependencyUpdatesTask : DefaultTask() { // tasks can't be final
   @Input
   var checkConstraints: Boolean = false
 
+  @Internal
+  var filterConfigurations: Spec<Configuration> = Spec<Configuration> { true }
+
   @Input
   var checkBuildEnvironmentConstraints: Boolean = false
 
@@ -124,7 +129,8 @@ open class DependencyUpdatesTask : DefaultTask() { // tasks can't be final
     val evaluator = DependencyUpdates(
       project, resolutionStrategyAction, revision,
       outputFormatter(), outputDir, reportfileName, checkForGradleUpdate,
-      gradleReleaseChannel, checkConstraints, checkBuildEnvironmentConstraints
+      gradleReleaseChannel, checkConstraints, checkBuildEnvironmentConstraints,
+      filterConfigurations
     )
     val reporter = evaluator.run()
     reporter.write()
diff --git a/gradle-versions-plugin/src/test/groovy/com/github/benmanes/gradle/versions/DependencyUpdatesSpec.groovy b/gradle-versions-plugin/src/test/groovy/com/github/benmanes/gradle/versions/DependencyUpdatesSpec.groovy
index 12a76ce9e..45190a409 100644
--- a/gradle-versions-plugin/src/test/groovy/com/github/benmanes/gradle/versions/DependencyUpdatesSpec.groovy
+++ b/gradle-versions-plugin/src/test/groovy/com/github/benmanes/gradle/versions/DependencyUpdatesSpec.groovy
@@ -611,6 +611,26 @@ final class DependencyUpdatesSpec extends Specification {
       undeclared.isEmpty()
     }
   }
+  @Issue('https://github.com/ben-manes/gradle-versions-plugin/issues/782')
+    def "Allow filtering configurations"() {
+    given:
+    def project = singleProject()
+    addDependenciesTo(project)
+    addRepositoryTo(project)
+
+    when:
+    def reporter = evaluate(project, 'milestone', null, 'build', null,null, false, RELEASE_CANDIDATE.id, {config -> config.name.equals("upgradesFound")})
+    reporter.write()
+
+    then:
+    with(reporter) {
+      unresolved.isEmpty()
+      upgradeVersions.size() == 2
+      upToDateVersions.isEmpty()
+      downgradeVersions.isEmpty()
+      undeclared.isEmpty()
+    }
+  }
 
   private static def singleProject() {
     return ProjectBuilder.builder().withName('single').build()
@@ -625,9 +645,10 @@ final class DependencyUpdatesSpec extends Specification {
 
   private static def evaluate(project, revision = 'milestone', outputFormatter = null,
     outputDir = 'build', resolutionStrategy = null, reportfileName = null,
-    checkForGradleUpdate = true, gradleReleaseChannel = RELEASE_CANDIDATE.id) {
+    checkForGradleUpdate = true, gradleReleaseChannel = RELEASE_CANDIDATE.id,
+    configurationFilter = { true }) {
     new DependencyUpdates(project, resolutionStrategy, revision, buildOutputFormatter(outputFormatter), outputDir,
-      reportfileName, checkForGradleUpdate, gradleReleaseChannel).run()
+      reportfileName, checkForGradleUpdate, gradleReleaseChannel, false, false, configurationFilter).run()
   }
 
   private static OutputFormatterArgument buildOutputFormatter(outputFormatter) {