【问题标题】:SBT: describe external dependency relative to another (transitive) dependency?SBT:描述相对于另一个(传递)依赖的外部依赖?
【发布时间】:2020-07-07 08:37:32
【问题描述】:

为了避免 jar hell,我想相对地引用一个依赖项。

例如,当我向"org.http4s" %% "https-circe" % "0.21.1"添加依赖时:

cs resolve org.http4s:http4s-circe_2.12:0.21.1 | grep -i circe                                                                                ⎈ eks-cluster-eu-west-1-dev/master
io.circe:circe-core_2.12:0.13.0:default

我想在版本中添加对"circe-literal" 的依赖项,该依赖项已由 SBT 的调解器自动解决。在这个例子中"0.13.0"。这可能吗?

【问题讨论】:

    标签: sbt dependency-management ivy coursier


    【解决方案1】:

    一方面,您可以添加带有通配符版本的circe-literal,使用latest-compatible 冲突管理器将获得与circe-core 兼容的版本。遗憾的是,如果不借助 coursier 插件,就无法为特定工件指定冲突管理器。

    如果没问题,但是,您应该可以指定:

    conflictManager := ConflictManager.latestCompatible
    libraryDependencies += "io.circe" %% "circe-literal % "[0,)"
    

    不过,您必须使用 ivy 解析器才能使其正常工作。

    dependencyResolution := sbt.librarymanagement.ivy.IvyDependencyResolution(ivyConfiguration.value)
    

    使用它,我得到了你想要的:

    [info]  [SUCCESSFUL ] io.circe#circe-literal_2.12;0.13.0!circe-literal_2.12.jar (304ms)
    

    【讨论】:

    • 这很好 - 谢谢。如果circe-literal 的版本不受任何(传递)依赖项的约束,我能否以某种方式指定它应该失败,例如如果没有指定对 "org.http4s" %% "https-circe" 的依赖,并且在该时间点解决了最新的在线依赖?
    • @StefanK。可能是。 Ivy 允许自定义版本管理器,在这种情况下,您实际上可以查找其他依赖项以确定您需要什么依赖项,否则会失败。不过,我不知道是否可以将它与 sbt 一起使用——我看到了 ant 的文档。而且,看起来工作量很大。
    猜你喜欢
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 2017-09-10
    • 2014-11-06
    • 2018-07-06
    • 2019-11-04
    相关资源
    最近更新 更多