question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simplified resolutionStrategy

See original GitHub issue

Update: Released in v0.25.0

Hello Ben,

I propose to add a declarative filter for filtering version

rejectVersionIf {
    isNonStable(candidate.version) && !isNonStable(currentVersion)
}

instead of

  resolutionStrategy {
    componentSelection {
      all {
        if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
          reject("Release candidate")
        }
      }
    }
  }

Also I noticed that people are much more creative on how they name their unstable versions than on how they name their unstable versions.

So the README should recommand something like:

fun isNonStable(version: String): Boolean {
  val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
  val regex = "^[0-9,.v-]+$".toRegex()
  val isStable = stableKeyword || regex.matches(version)
  return isStable.not()
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:26 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
ben-manescommented, Sep 18, 2019

When I try the examples/groovy I get the error:

Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'candidate' for task ':dependencyUpdates' of type com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask.
  ...
  at com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentFilter$reject.call(Unknown Source)
  at com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask$_rejectVersionIf_closure2$_closure3$_closure4.doCall(DependencyUpdatesTask.groovy:102)

It works if I explicitly qualify candidate, e.g.

rejectVersionIf { 
  isNonStable(it.candidate.version)
}

Perhaps this means that the closure’s delegate isn’t being set up?

1reaction
ferinagycommented, Sep 5, 2019

Just for inspiration, in our project I use:

resolutionStrategy {
    componentSelection {
        all {
            fun String.stability(): Int = when {
                this.contains("alpha") -> 0
                this.contains("beta") -> 1
                this.contains("rc") -> 2
                else -> 3
            }

            if (candidate.version.stability() < currentVersion.stability()) {
                reject("Do not offer less stable version")
            }
        }
    }
}

It is not catching every possible naming convention, but it works for our dependencies, is pretty easily extensible and offers updates to more stable version in case you use some alpha/beta because you take the risk and do not want to wait until it becomes stable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ResolutionStrategy (Gradle API 7.6)
Defines the sort order for components and artifacts produced by the configuration. Method Summary. All Methods Instance Methods Abstract ...
Read more >
How to use Gradle resolutionStrategy to force dependency ...
This code snippet will find each dependency who has group name com.android.support and forcefully apply the version 28.0.0 , even to the ...
Read more >
Customizing Dependency Resolution Behavior - API Manual
For more information and code samples see the ResolutionStrategy class in ... But it is easy for transitive dependency resolution to violate this...
Read more >
Manage Gradle version conflicts with resolution strategy
Gradle version catalogs for an awesome dependency management ... Managing dependencies in a single module project is pretty simple, but when you ...
Read more >
Reduced Target-Resolution Strategy for Rapid Multi-Observer ...
The strategy offers a simple and easy-to-replicate process and does not require any elaborate site/demand abstraction processes or ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found