Dependency Constrains clarification


(Leigh Cooper) #1

I came across the following disclaimer while reading the article about Managing Transitive Dependencies https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:dependency_constraints

Dependency constraints are not yet published, but that will be added in a future release. This means that their use currently only targets builds that do not publish artifacts to maven or ivy repositories.

Does this quote mean that dependency constraints is a future feature and not yet supported?

I’m not sure what this means, does this mean that dependency constrains can’t be used in projects which publishes artefacts to Maven/Ivy? I’m not sure I understand why this would be the case. Why would dependency resolution affect publishing artefacts?


(Louis Jacomet) #2

When using dependency constraints you can alter the dependency graph resolution, diverging from the resolved graph you would obtain without constraints.

If your component is a library, when it is published to be consumed by others, since constraints are currently not published in the Ivy or Maven format, these consumers may not be able to resolve transitive dependencies the same way your library resolved and tested with them.

This could cause unexpected dependency issues to your consumers. This is why the documentation currently recommends not using constraints unless you are developing a component which is not to be consumed by other components.

Note that there are plugins out there that will publish resolved dependency versions, such as the nebula-publishing-plugin. Their use makes this remark irrelevant.


(Leigh Cooper) #3

Ah yes I understand. Thanks for taking the time to explain that, and for the plugin recommendation.