5

If my project requires dependency com.abc:xyz:1.2.0, and I have another dependency that transitively wants com.abc:xyz:2.0.0, this is a major problem because even if my project compiles, there could be behavior differences. For some reason in this case, Gradle assumes that using 2.0.0 will be no problem at all and chooses 2.0.0.

I want to fail in this case. I am aware of failOnVersionConflict(), but this raises errors even when the patch segments don’t match. How can I fail only when there is major version conflict?

Thanks

GreenSaguaro
  • 2,968
  • 2
  • 22
  • 41
  • 1
    You could adapt the following example to check if the major version of the requested dependency is different than the one you want and fail instead of forcing a version. – JB Nizet Sep 30 '18 at 08:22
  • Sorry, forgot to post the example: https://docs.gradle.org/current/userguide/customizing_dependency_resolution_behavior.html#example_blacklisting_a_version_with_a_replacement – JB Nizet Sep 30 '18 at 08:29
  • have you managed to sort it out? the link above is dead – s4nk Aug 17 '20 at 15:12
  • The only way that I know of to do this would be do add some kind of version processor hook – GreenSaguaro Aug 17 '20 at 15:30
  • Did you find a solution after all? – peshkira Sep 03 '20 at 14:35
  • @peshkira See my previous comment. – GreenSaguaro Sep 04 '20 at 05:50
  • Yes thanks. Unfortunately, it is not very helpful. I am trying to research Gradle's Rich versions and they might help, but the problem is that they are not compatible with Maven unless you use Gradle Module Metadata. So I am trying also to figure out if there is another way. Your comment does not help me right now, but if you have a specific idea or example or link, it will be much appreciated, @GreenSaguaro. – peshkira Sep 04 '20 at 13:37
  • I am not sure ultimately what you are trying to achieve, but perhaps look at the Gradle Spring BOM plugin. This code may dive deep into the API of intercepting and changing dependency versions. Additionally, I would explore the Gradle API https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html and the Gradle DSL https://docs.gradle.org/current/dsl/index.html. @peshkira – GreenSaguaro Sep 04 '20 at 17:46

0 Answers0