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

Resolve dependency constraints. #351

Merged
merged 3 commits into from
Oct 10, 2019

Conversation

anuraaga
Copy link
Collaborator

@anuraaga anuraaga commented Oct 8, 2019

Dependency constraints can be used to set versions, and in particular can be used with the java-platform plugin to define all constraints in a single location. It would be convenient if these constraints were resolved by the plugin since then instead of resolving the dependencies of all projects in a monorepo controlled by a platform, just need to resolve a single project for better performance and simpler output.

I am wondering whether this feature should be restricted to projects with the java-platform plugin. Let me know if you have thoughts.

Reference

Fixes #350

@jmfayard
Copy link
Collaborator

jmfayard commented Oct 8, 2019

Looks promising to me.

Can you add an example of use in the samples?
You can then try it with:

# Publish the latest version of the plugin to mavenLocal()
$ ./gradlew install  

# Try out the samples
$ ./gradlew -p examples/groovy dependencyUpdate
$ ./gradlew -p examples/kotlin dependencyUpdate

@anuraaga
Copy link
Collaborator Author

anuraaga commented Oct 9, 2019

Thanks - added examples

configuration.dependencyConstraints.each { dependency ->
latest.add(createQueryDependency(dependency, revision))
}
} catch (MissingPropertyException e) {
Copy link
Owner

Choose a reason for hiding this comment

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

In other cases we've guarded using metaClass.respondsTo("..."). Which do you consider preferable?

@@ -149,6 +159,19 @@ class Resolver {
}
}

/** Returns a variant of the provided dependency used for querying the latest version. */
@TypeChecked(SKIP)
private Dependency createQueryDependency(DependencyConstraint dependency, String revision) {
Copy link
Owner

Choose a reason for hiding this comment

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

Its probably not simpler to combine this with the other createQueryDependency, though the duplication could lead to mistakes of fixing one instead of both.

@ben-manes
Copy link
Owner

Thanks for the PR and test case. I think it makes sense to go in. What do you think @jmfayard?

Would constraints someday be used to implement BOMs or are they totally separate? My only concern is if someone has a large BOM but only uses a few dependencies, and the constraint resolution causes them to see the universe. That seems unlikely but worth asking.

@jmfayard
Copy link
Collaborator

jmfayard commented Oct 9, 2019

I have no further remarks. I learned a lot of new things by reading the two links from the PR

@anuraaga
Copy link
Collaborator Author

Switched to using respondsTo.

It's an interesting question of if in the future, Gradle would internally implement a BOM dependency by translating it into constraints. I feel as if this wouldn't happen, since a Configuration basically reflects the settings of the project and such opaque translation would probably not happen at that layer, BOM's work fine just using the normal dependency resolver already. I am more worried about if some other plugin, like nebula, does such translation as it could be a way to support BOM for old versions of Gradle that didn't natively resolve them - it's probably a bit too much though to worry about interactions with other plugins unless getting a report IMO.

@ben-manes ben-manes merged commit c926953 into ben-manes:master Oct 10, 2019
@ben-manes
Copy link
Owner

That makes sense. Thanks again. 😄

@ben-manes
Copy link
Owner

Releasing v26.

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.

Resolve versions in a java-platfom project
3 participants