-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplified resolutionStrategy #325
Comments
Thanks, it’s very nice. Unfortunately it has to be empty by default. We don’t want to change behavior so opt-in rather than your opt-out. |
Yes, that was my intention as well. |
This looks quite nice - quite a bit cleaner than the current approach. |
i was thinking how to integrate it with the newest feature we could have rejectVersionContaining ("alpha","beta",...)
which would be a shorter version of rejectVersionIf { candidate ->
listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea").any { qualifier ->
candidate.version.matches(Regex("(?i).*[.-]\$qualifier[.\\d-+]*"))
}
}
which would be a shorter version of resolutionStrategy {
componentSelection {
all {
fun isNonStable(version: String) = listOf("alpha", "beta", "rc", "cr", "m", "preview", "b", "ea").any { qualifier ->
version.matches(Regex("(?i).*[.-]\$qualifier[.\\d-+]*"))
}
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject("Release candidate")
}
}
}
}
|
Yes, that sounds very nice. Please note that @ghus-raba and I need to debug #331 a bit to fix backwards compatibility mistakes. So the newest feature might be a little in flux, as in it might be a very trivial fix or maybe we broke the general contract. I'm hopeful that it is only a minor mistake and I'll dig into it over the weekend. So please don't make any firm commitments in your code until we've worked that issue out. |
@ben-manes I just had a random thought under the shower. A GitHub code search on As far I can see it would be be quite doable to write the right function fun isStableVersion(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL").any { version.contains(it) }
val regex = "^[0-9,.v-]+$".toRegex()
return stableKeyword || regex.matches(version)
} |
True, I'm fine switching the example and if you want to use that in your simplified setting. Maven treats GA and FINAL as aliases, but not RELEASE. Some projects annoyingly use even/odd versions to distinguish between release/beta. I think we should be careful not to get into being the owners of this list and always defer to users who will have some awkward scenario. |
That's wise :) With version 0.24.0 being released, I can now work on this right? |
Oh yeah, please do :) |
Just for inspiration, in our project I use:
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. |
Cannot change dependencies of configuration ':classpath' after it has been resolved. https://gist.github.com/jmfayard/f8455c2cdc658035e8d542ecf0f841ac
Implements #325 rejectVersionIf { ... }
Thanks @jmfayard! :) |
@ben-manes the gradlePluginPortal shows version 0.24.0 while mavenCentral has 0.25.0 |
Yes, it takes a little while for the plugin portal to be sync'd. The portal is in fact s JCenter repository anyway. We use that integration, which was the required setup when the plugin portal first launched. Probably now you can deploy directly to the plugin portal if starting from scratch. |
Just checked, and its on the plugin portal now |
the simplified strategy isn't working for multi-module project. |
Didn't work for me either on a single-module project; I also had to use example 3. |
When I try the
It works if I explicitly qualify rejectVersionIf {
isNonStable(it.candidate.version)
} Perhaps this means that the closure's delegate isn't being set up? |
@ghus-raba Any chance you know how to fix the above issue? I haven't dug in, but I think it's like the trick you did before to make |
Doesn't it depend on the Gradle version? examples/groovy did work for me when I was using current Gradle, before I refactored it to use the Gradle wrapper of the plug-in |
|
I just tried again and cannot reproduce it anymore in the examples. |
EDIT, the readme is wrong it seems, you need to name the context object e.g. Got the same issue with the missing property, using the script configured as this. def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { qualifier -> version.toUpperCase().contains(qualifier) }
def regex = /^[0-9,.v-]+$/
return !stableKeyword && !(version ==~ regex)
}
dependencyUpdates {
revision = "release"
rejectVersionIf {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}
} stacktrace``` Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'candidate' for task ':dependencyUpdates' of type com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask. at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:84) at org.gradle.internal.metaobject.ConfigureDelegate.getProperty(ConfigureDelegate.java:130) at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190) at groovy.lang.Closure.getProperty(Closure.java:298) at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:190) at groovy.lang.Closure.getPropertyTryThese(Closure.java:319) at groovy.lang.Closure.getPropertyOwnerFirst(Closure.java:313) at groovy.lang.Closure.getProperty(Closure.java:302) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:309) at dependencies_help_5g5jr2o0p3sgnk3afqa3iojhi$_run_closure3$_closure11.doCall(/Users/bric3/blablacar/services/edge-api/gradle/dependencies-help.gradle:38) at jdk.internal.reflect.GeneratedMethodAccessor74.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:104) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:326) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) at groovy.lang.Closure.call(Closure.java:411) at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:50) at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:122) at com.sun.proxy.$Proxy68.reject(Unknown Source) 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) at jdk.internal.reflect.GeneratedMethodAccessor72.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:104) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:326) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:127) at com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionRulesWithCurrent$2.execute(ComponentSelectionRulesWithCurrent.groovy:37) at com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionRulesWithCurrent$2.execute(ComponentSelectionRulesWithCurrent.groovy) at org.gradle.internal.rules.NoInputsRuleAction.execute(NoInputsRuleAction.java:38) at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ComponentSelectionRulesProcessor.processRule(ComponentSelectionRulesProcessor.java:84) ```Gradle 5.6.2 (with the wrapper of course) |
Can you delete your .gradle dir? I had done a git clean -dfx and killed the daemons. Then it worked. |
@ben-manes thanks it seems most of my issues were related to the context object Although my script only the last |
The readme is definitely wrong. I don't think there's a bug in the feature but rather a limitation of how The wrong example snippet from the current readme: dependencyUpdates {
// Example 1: reject all non stable versions
rejectVersionIf {
isNonStable(candidate.version)
}
// Example 2: disallow release candidates as upgradable versions from stable versions
rejectVersionIf {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}
// Example 3: using the full syntax
resolutionStrategy {
componentSelection {
all {
if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
reject('Release candidate')
}
}
}
}
} Instead this snippet should be rewritten like this (and maybe for the kotlin snippet as well, I didn't check): // Example 1: reject all non stable versions
dependencyUpdates {
rejectVersionIf { selection ->
isNonStable(selection.candidate.version) // <---- notice the arg name
}
} // Example 2: disallow release candidates as upgradable versions from stable versions
dependencyUpdates {
rejectVersionIf {
isNonStable(it.candidate.version) && !isNonStable(it.currentVersion) // <---- notice the it (standard groovy)
}
} // Example 3: using the full syntax
dependencyUpdates {
resolutionStrategy {
componentSelection {
all {
if (isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)) {
reject('Release candidate')
}
}
}
}
} |
Update: Released in v0.25.0
Hello Ben,
I propose to add a declarative filter for filtering version
instead of
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:The text was updated successfully, but these errors were encountered: