Best practice to solve dependency conflicts

865 views
Skip to first unread message

Johannes Rudolph

unread,
Nov 22, 2011, 4:32:57 AM11/22/11
to simple-b...@googlegroups.com
What is the preferred way to solve (Ivy-) conflicts once they arrive? AFAIK sbt configures ivy to use the 'latest-revision' conflict manager which is probably the most optimistic choice because it assumes that newer packages are backward compatible in all cases. 

In cases where you have to choose manually what should happen I can see two ways how to configure Ivy to do what you want:
a) allow setting of the `force`-attribute for dependencies
b) allow adding a conflict manager for a module similar to what the `<conflict>` tag allows in ivy.xmls [1]

Here's what I came up with:

  def addConflictManager(org: String, name: String, conflictManager: String) =
    ivyModule <<= (ivyModule, streams) map { (module, s) =>
      module.withModule(s.log) { (ivy, desc, _) =>
        import _root_.org.apache.ivy.{core, plugins}
        import core.module.id.ModuleId
        import plugins.matcher.PatternMatcher

        desc.addConflictManager(
          ModuleId.newInstance(org, name),
          ivy.getSettings.getMatcher(PatternMatcher.EXACT),
          ivy.getSettings.getConflictManager("latest-compatible"))
        module
      }
    }

You can use that to declare a conflict manager for a single dependency. 

Johannes


Indrajit Raychaudhuri

unread,
Nov 22, 2011, 9:44:38 AM11/22/11
to simple-b...@googlegroups.com
Hi Johannes,

If this is a 'one off' case for a specific library, you can try applying the ExclusionRule on the library which is transitively bringing in the library in question.

Thus you can do something like this:
lazy val dep = "org.example" % "lib1" % "version" exclude("org.example", "new_lib")

Does this work for you?

- Indrajit

> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/simple-build-tool/-/Xw0XPZSYXD4J.
> To post to this group, send email to simple-b...@googlegroups.com.
> To unsubscribe from this group, send email to simple-build-t...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/simple-build-tool?hl=en.

Mark Harrah

unread,
Nov 22, 2011, 5:32:11 PM11/22/11
to simple-b...@googlegroups.com
Hey Johannes,

On Tue, 22 Nov 2011 01:32:57 -0800 (PST)
Johannes Rudolph <johannes...@gmail.com> wrote:

> What is the preferred way to solve (Ivy-) conflicts once they arrive? AFAIK
> sbt configures ivy to use the 'latest-revision' conflict manager which is
> probably the most optimistic choice because it assumes that newer packages
> are backward compatible in all cases.

I chose this because it was Ivy's default (I think, at least).

> In cases where you have to choose manually what should happen I can see two
> ways how to configure Ivy to do what you want:
> a) allow setting of the `force`-attribute for dependencies
> b) allow adding a conflict manager for a module similar to what the
> `<conflict>` tag allows in ivy.xmls [1]

The code in sbt wrapping Ivy has been implemented incrementally as user need for various Ivy features arises. It would have been far too much to wrap it all at once, not to mention that I didn't really understand all of Ivy's features when I started (not that I understand everything now).

So... What you have done is the way I would do it as well, but feel free to submit a patch to extend the Ivy-wrapping API to support this and a setting to configure it. I expect the common case is to set the default conflict manager, but it looks like you needed to set the per-dependency conflict manager as well.


-Mark

Reply all
Reply to author
Forward
0 new messages