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

WIP: rejectVersionIf { }  #337

Closed
wants to merge 2 commits into from
Closed

WIP: rejectVersionIf { }  #337

wants to merge 2 commits into from

Conversation

jmfayard
Copy link
Collaborator

@jmfayard jmfayard commented Sep 6, 2019

I had a first try at implementing #325

rejectVersionIf { current: ComponentSelectionWithCurrent ->
        isNonStable(current.candidate.version) || !isNonStable(current.currentVersion)
}

It would be better if we can change the syntax to this but I don't know how to do it:

rejectVersionIf { candidate: ModuleComponentIdentifier ->
        isNonStable(candidate.version) || !isNonStable(currentVersion)
}

isNonStable being defined as this:

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()
}

Since my Groovy skills are closed to zero, I tried to upgrade Gradle so that at least that part is familiar for me.

Because of the Gradle update, one test is not working anymore https://scans.gradle.com/s/unwddfvrt5xak

    > Could not find method componentSelection() for arguments [build_6aatid6bxisq96bm8bf31j5zh$_run_closure3$_closure5@243ebea0] on root project 'junit8907024250739898265' of type org.gradle.api.Project.

dependencyUpdates.resolutionStrategy = componentSelection {
        all(new Rule())
   }
}

I have also run ./gradlew publish and then use the artifact in my own plugin

https://github.com/jmfayard/buildSrcVersions/pull/62/files

One part of this is also wrong:

Cannot change dependencies of configuration ':classpath' after it has been resolved.

https://gist.github.com/jmfayard/f8455c2cdc658035e8d542ecf0f841ac

Jean-Michel Fayard added 2 commits September 6, 2019 16:39
One test is not working anymore:

    > Could not find method componentSelection() for arguments [build_6aatid6bxisq96bm8bf31j5zh$_run_closure3$_closure5@243ebea0] on root project 'junit8907024250739898265' of type org.gradle.api.Project.

https://scans.gradle.com/s/unwddfvrt5xak

```
dependencyUpdates.resolutionStrategy =
    componentSelection {
        all(new Rule())
   }
}
```
@jmfayard jmfayard requested a review from ben-manes September 6, 2019 15:38
@ben-manes
Copy link
Owner

If you use gradle install it will install into the local maven repository. Then you can use mavenLocal() in your repository to reference it, if you bump the version up. That's how I do ad hoc testing in the examples build, to see it in action.

I think Gradle changed the version of Groovy which is backwards incompatible, so we stayed on an old version which is forward compatible. So there could be some weird interaction there.

If you drop all your Gradle changes and use mavenLocal, does all of this work right?

@@ -91,6 +98,18 @@ class DependencyUpdatesTask extends DefaultTask {
this.resolutionStrategy = null
}

void rejectVersionIf(final Transformer<Boolean, ComponentSelectionWithCurrent> filter) {
resolutionStrategy { ResolutionStrategyWithCurrent strategy ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like you can now drop the these now that the delegation is fixed. Does it work like this?

resolutionStrategy {
  strategy.componentSelection {
    all {
      if (filter.transform(current)) {
        current.reject("Rejected")
      }
    }
  }
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, maybe not without losing the typesafe checking

Object outputFormatter = 'plain'

@Input @Optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing the fail in the test, because the closure is executed without correct arguments and delegates during validation. Something similar seems to have happened in 3cce551, where they removed the annotation from the outputFormatter field.

Map<Project, Set<Configuration>> projectConfigs = project.allprojects.collectEntries { proj ->
[proj, proj.configurations.plus(proj.buildscript.configurations) as Set]
Map<Project, ConfigurationContainer> projectConfigs = project.allprojects.collectEntries { proj ->
proj.configurations.addAll(proj.buildscript.configurations)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be the cause of Cannot change dependencies of configuration ':classpath' after it has been resolved. Try:

def configurations = []
configurations.addAll(proj.configurations)
configurations.addAll(proj.buildscript.configurations)
[proj, configurations as Set]

@jmfayard jmfayard closed this Sep 9, 2019
@jmfayard jmfayard deleted the 325-rejectVersionIf branch October 8, 2019 09:19
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

Successfully merging this pull request may close these issues.

3 participants