Skip to content
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

Breaking change in 0.23.0? #331

Closed
stumacsolutions opened this issue Aug 30, 2019 · 17 comments
Closed

Breaking change in 0.23.0? #331

stumacsolutions opened this issue Aug 30, 2019 · 17 comments

Comments

@stumacsolutions
Copy link

I've just picked up the new version of your library and we now get the following error when running useLatestVersions:

Could not set unknown property 'resolutionStrategy' for task ':dependencyUpdates' of type com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask.

If we change our gradle config from dependencyUpdates.resolutionStrategy to
dependencyUpdates.resolutionStrategyAction things work as before.

Just wondering if this was an intentional change or not before we roll this fix out across our projects?

@augi
Copy link

augi commented Aug 30, 2019

I have the same problem (tested with Gradle 5.6 and 5.6.1):
Could not set unknown property 'resolutionStrategy' for task ':client:dependencyUpdates' of type com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask.

@johnjohndoe
Copy link
Contributor

The version itself runs for me. However, if I apply the latest resolutionStrategy snippet from the README.md there is no version being output.

"Old" resolution strategy

dependencyUpdates.resolutionStrategy {
    componentSelection { rules ->
        rules.all { ComponentSelection selection ->
            boolean rejected = ["alpha", "beta", "rc", "cr", "m", "preview", "b", "ea"].any { qualifier ->
                selection.candidate.version ==~ /(?i).*[.-]$qualifier[.\d-+]*/
            }
            if (rejected) {
                selection.reject("Release candidate")
            }
        }
    }
}

Output

> Task :dependencyUpdates
Failed to resolve :app:debugAndroidTestCompileClasspath
Failed to resolve :app:debugCompileClasspath
Failed to resolve :app:debugUnitTestCompileClasspath
Failed to resolve :app:releaseCompileClasspath
Failed to resolve :app:releaseUnitTestCompileClasspath
Failed to resolve :roadsigns:debugAndroidTestCompileClasspath
Failed to resolve :roadsigns:debugCompileClasspath
Failed to resolve :roadsigns:debugUnitTestCompileClasspath
Failed to resolve :roadsigns:releaseCompileClasspath
Failed to resolve :roadsigns:releaseUnitTestCompileClasspath

------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------

The following dependencies are using the latest milestone version:
 - com.android.support.constraint:constraint-layout:1.1.3
 - com.android.support.test:rules:1.0.2
 - com.android.support.test.espresso:espresso-core:3.0.2
 - com.android.tools.build:aapt2:3.5.0-5435860
 - com.android.tools.build:gradle:3.5.0
 - com.android.tools.lint:lint-gradle:26.5.0
 - com.github.ben-manes:gradle-versions-plugin:0.23.0
 - com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4
 - digital.wup:android-maven-publish:3.6.2
 - org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50
 - org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50

The following dependencies have later milestone versions:
 - com.android.support:appcompat-v7 [27.1.1 -> 28.0.0]
     http://developer.android.com/tools/extras/support-library.html
 - com.android.support:support-annotations [27.1.1 -> 28.0.0]
     http://developer.android.com/tools/extras/support-library.html
 - com.android.support:support-vector-drawable [27.1.1 -> 28.0.0]
     http://developer.android.com/tools/extras/support-library.html

Gradle current updates:
 - Gradle: [5.6.1: UP-TO-DATE]

"New" resolution strategy

dependencyUpdates.resolutionStrategy {
    componentSelection { rules ->
        rules.all {
            def isNonStable = { String version ->
                ["alpha", "beta", "rc", "cr", "m", "preview", "b", "ea"].any { qualifier ->
                    version ==~ /(?i).*[.-]\$qualifier[.\\d-+]*/
                }
            }
            if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
                selection.reject("Release candidate")
            }
        }
    }
}

Output

> Task :dependencyUpdates
Failed to resolve :app:debugAndroidTestCompileClasspath
Failed to resolve :app:debugCompileClasspath
Failed to resolve :app:debugUnitTestCompileClasspath
Failed to resolve :app:releaseCompileClasspath
Failed to resolve :app:releaseUnitTestCompileClasspath
Failed to resolve :roadsigns:debugAndroidTestCompileClasspath
Failed to resolve :roadsigns:debugCompileClasspath
Failed to resolve :roadsigns:debugUnitTestCompileClasspath
Failed to resolve :roadsigns:releaseCompileClasspath
Failed to resolve :roadsigns:releaseUnitTestCompileClasspath

------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------

Failed to determine the latest version for the following dependencies (use --info for details):
 - com.android.support:appcompat-v7
 - com.android.support:support-annotations
 - com.android.support:support-vector-drawable
 - com.android.support.constraint:constraint-layout
 - com.android.support.test:rules
 - com.android.support.test.espresso:espresso-core
 - com.android.tools.build:aapt2
 - com.android.tools.build:gradle
 - com.android.tools.lint:lint-gradle
 - com.github.ben-manes:gradle-versions-plugin
 - com.jfrog.bintray.gradle:gradle-bintray-plugin
 - digital.wup:android-maven-publish
 - org.jetbrains.kotlin:kotlin-gradle-plugin
 - org.jetbrains.kotlin:kotlin-stdlib-jdk8

Gradle current updates:
 - Gradle: [5.6.1: UP-TO-DATE]

@ben-manes
Copy link
Owner

Sorry, this was unintentional. I’ll have a fix out by the end of the weekend.

cc @ghus-raba

@ferinagy
Copy link
Collaborator

  1. Sample from readme:
dependencyUpdates.resolutionStrategy {
    componentSelection { rules ->
        rules.all {
            def isNonStable = { String version ->
                ["alpha", "beta", "rc", "cr", "m", "preview", "b", "ea"].any { qualifier ->
                    version ==~ /(?i).*[.-]\$qualifier[.\\d-+]*/
                }
            }
            if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
                selection.reject("Release candidate")
            }
        }
    }
}

Sorry, there is extra escape in the readme. It was fixed in #332. There should be version ==~ /(?i).*[.-]$qualifier[.\d-+]*/

  1. Could not set unknown property

I have the same problem (tested with Gradle 5.6 and 5.6.1):
Could not set unknown property 'resolutionStrategy' for task ':client:dependencyUpdates' of type com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask.

Can you post your resolutionStrategy, or some reproducible code? It seems you are accessing a property of the task

Action<? super ResolutionStrategyWithCurrent> resolutionStrategyAction = null
instead of a method
void resolutionStrategy(final Action<? super ResolutionStrategyWithCurrent> resolutionStrategy) {

@ben-manes
Copy link
Owner

ben-manes commented Aug 30, 2019

@ghus-raba I accidentally exposed the property instead of using the method, not being super great at Groovy and doing things ad hoc over weekends. In 894fbdf, I showed documentation which used = instead of a method. So unfortunately we should keep that working for backwards compatibility.

dependencyUpdates.resolutionStrategy = {
  componentSelection { rules ->
    rules.all { ComponentSelection selection ->
      boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier ->
        selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
      }
      if (rejected) {
        selection.reject('Release candidate')
      }
    }
  }
}

@ferinagy
Copy link
Collaborator

Ok, then renaming the property back to be same as method should do the trick. I think I changed it because of a codenarc warning. Although it changed from Closure to Action, so it might not work out of the box. Then if we want to keep it working, we would have to revert back to Closure and handle it in Resolver a bit differently.

@ben-manes
Copy link
Owner

I think the change from Closure to Action is compatible enough if the types are inferred by the build scripts. If the 99% case works and one plugin integration has to revise, then I think it's a fine break. If it leaks into the general case then a little adapter code can probably be done at the task prior to the Resolver (e.g. adapt from the Closure to Action before going downstream).

@johnjohndoe
Copy link
Contributor

If you still need a project to try out the behavior you are invited to use mine.

@ben-manes
Copy link
Owner

Released version 0.24.

The direct assignment of the dependencyUpdates.resolutionStrategy property is supported again, but will issue a deprecation warning. Instead of an explicit =, prefer the DSL style of an assignment method.

// old style
dependencyUpdates.resolutionStrategy = { ... }
// proper style
dependencyUpdates.resolutionStrategy { ... }

This deprecated usage will show up as a build warning like other Gradle feature deprecations, where a detailed message is shown when running with --warning-mode=all.

@johnjohndoe
Copy link
Contributor

johnjohndoe commented Sep 1, 2019

Do you know why the dependencyUpdates task outputs the following?

Failed to resolve :app:debugAndroidTestCompileClasspath
...

@johnjohndoe
Copy link
Contributor

johnjohndoe commented Sep 1, 2019

I tested version 0.24 with the latest resolutionStrategy. It outputs this:

The following dependencies exceed the version found at the milestone revision level:
 - com.android.tools.build:gradle [3.5.0 <- 2.3.0]

while 0.24 with the former resolutionStrategy correctly outputs:

The following dependencies are using the latest milestone version:
 - com.android.tools.build:gradle:3.5.0

You can try out the behavior on this temporary branch.

@ben-manes
Copy link
Owner

I think that is because selection is not defined as the input argument, causing the reject(...) method to fail or not take effect. If you add ComponentSelection selection -> does that seem correct?

dependencyUpdates.resolutionStrategy {
  componentSelection { rules ->
    rules.all { ComponentSelection selection ->
      def isNonStable = { String version -> 
        ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'b', 'ea'].any { qualifier ->
          version ==~ /(?i).*[.-]$qualifier[.\d-+]*/
        }
      }

      if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
        selection.reject('Release candidate')
      }
    }
  }
}

@ben-manes
Copy link
Owner

In regards to the configuration resolution failures, that seems to be an Android / Gradle bug. See #326 - they don't the handle detached configurations, e.g. like ours created by Configuration.copy(). You would need to ask those teams to resolve their oversight.

@johnjohndoe
Copy link
Contributor

If you add ComponentSelection selection -> does that seem correct?

Applying your snippet produces the expected output. 👍 Thanks for your quick response.
I updated my branch.

@stumacsolutions
Copy link
Author

Massive thanks for the quick response and fix, and I will migrate away from the deprecated configuration straight away.

@ferinagy
Copy link
Collaborator

ferinagy commented Sep 2, 2019

@johnjohndoe BTW both rules -> and ComponentSelection selection -> should not be necessary anymore, as the closures should have proper delegates set. So even this should be ok:

dependencyUpdates.resolutionStrategy {
  componentSelection {
    all {
      def isNonStable = { String version -> 
        ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'b', 'ea'].any { qualifier ->
          version ==~ /(?i).*[.-]$qualifier[.\d-+]*/
        }
      }

      if (isNonStable(candidate.version) && !isNonStable(currentVersion)) {
        reject('Release candidate')
      }
    }
  }
}

@johnjohndoe
Copy link
Contributor

johnjohndoe commented Sep 3, 2019

@ghus-raba Thanks. Looks good to me. I updated my branch. Please update the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants