SBT依赖于特定的快照版本

时间:2012-08-31 10:40:00

标签: scala maven sbt

我有多个快照版本的神器,例如artifact-0.1-20120831.103456-5

我的项目取决于特定的快照版本。 如果我告诉SBT下载0.1-20120831.103456-5版本而不是0.1-SNAPSHOT,则更新任务失败。

// build.sbt
libraryDependencies ++= Seq(
"com.example" % "smith" % "0.1-20120906.110133-36")

// sbt update
[warn] ==== My Repo snapshots: tried
[warn]   http://repo.localhost/snapshots/com/example/smith/0.1-20120906.110133-36/commons-0.1-20120906.110133-36.pom

如何在http://repo.localhost/snapshots/com/example/smith/0.1-SNAPSHOT目录中制作SBT搜索工件,但使用唯一的快照版本?

3 个答案:

答案 0 :(得分:5)

Addition 除了独特的版本插件外,sbt还有aether-deploy插件(见下文)。

unique version plugin可让您按照自己的意愿解决工件问题。从页面引用:

  

如何指出

"0.1.0" or "0.1.0-20120602-073010" you can always use the static version number.
"0.1.0-+" selects the latest 0.1.0 snapshot.
"latest.integration" selects the latest revision regardless of its status.
"latest.milestone" selects the latest revision with either Milestone or Release status.
"latest.release" selects the latest with the Release status.

但是您还必须使用此插件发布,因为工件以与版本不同的方式发布:在您的示例中,工件不会存储在0.1-SNAPSHOT目录下但在0.1-20120831.103456-5下< / p>

<强>加成 还有aether-deploy plugin使用Aether(Aether提供了与Maven存储库交互的标准方法)。问题是这个插件目前只适用于部署(如插件名称所示)。也许作者有计划扩展它以便它也可以解析(对我来说听起来像一个有用的功能)。如果您无法使用唯一版本插件发布(例如,如果快照不属于您),那么您可以在sbt forum处询问。

所以我无法提供一个像maven一样为您的用例工作的解决方案,但希望它能为您和其他人提供一些有用的信息。

答案 1 :(得分:2)

一个丑陋的解决方法是使用install:instal-file在您自己的groupId(比如smith.external)中安装快照artefact而不是作为SNAPSHOT 并声明所需的版本号,而不是声明快照的使用。

由于您不希望版本发生变化,您可以依赖此版本,直到您使用提供的稳定版本(以及常规groupId)

答案 2 :(得分:2)

不是最佳解决方案,但您可以尝试使用Ivy (see apache docs)提供的冲突管理器。例如,默认使用'latest-revision','latest-compatible'管理器应该禁止任何依赖冲突。

设置起来并不容易,但谷歌sbt小组的someone发布了以下规则:

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
    }
  }
相关问题