Skip to content

Commit

Permalink
Merge pull request #785 from bh-tt/master
Browse files Browse the repository at this point in the history
Allow filtering configurations
  • Loading branch information
bh-tt committed Jun 9, 2023
2 parents 8c1ee4b + d63a2b9 commit 7d1fa03
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 }
) {

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit 7d1fa03

Please sign in to comment.