sbt:发布插件并从本地存储库中解析

时间:2018-03-14 18:38:10

标签: sbt ivy

我正在尝试将sbt插件发布到本地文件仓库。在插件的build.sbt中我有:

publishTo := Some(Resolver.file("localtrix", file("/Users/jast/repo/localtrix")))

我运行publish任务,并且发布得很好 /Users/jast/repo/localtrix/org/me/sbt-plugin_2.12_1.0/1.2.3

在另一个项目中,我想解决这个插件。在project/plugins.sbt我有:

resolvers += Resolver.file("localtrix", file("/Users/jast/repo/localtrix"))
addSbtPlugin("org.me" % "sbt-plugin" % "1.2.3")

我尝试在这个项目中运行sbt,然后得到:

[info] Updating ProjectRef(uri("file:/Users/jast/playspace/untitled38/project/"), "untitled38-build")...
[warn]  module not found: org.me#sbt-plugin;1.2.3
[warn] ==== typesafe-ivy-releases: tried
[warn]   https://repo.typesafe.com/typesafe/ivy-releases/org.me/sbt-plugin/scala_2.12/sbt_1.0/1.2.3/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.me/sbt-plugin/scala_2.12/sbt_1.0/1.2.3/ivys/ivy.xml/2017.2+4-3037ba82+20180314-1919/ivys/ivy.xml
[warn] ==== local: tried
[warn]   /Users/jast/.ivy2/local/org.me/sbt-plugin/scala_2.12/sbt_1.0/1.2.3/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/me/sbt-plugin_2.12_1.0/1.2.3/sbt-plugin-1.2.3.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /Users/jast/.sbt/preloaded/org.me/sbt-plugin/scala_2.12/sbt_1.0/1.2.3/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////Users/jast/.sbt/preloaded/org/me/sbt-plugin_2.12_1.0/1.2.3/sbt-plugin-1.2.3.pom
[warn] ==== localtrix: tried
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.me#sbt-plugin;1.2.3: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

那么如何才能以正确解析的方式发布到本地仓库呢?

注意:publishLocal并从.ivy2/local解析,但我希望能够发布到我可以复制到另一台计算机的仓库而不会弄乱该目录。

2 个答案:

答案 0 :(得分:1)

你错过了scala版本的名字。你在已发布的工件中的插件名_1.0中也有一个奇怪的后缀,所以修复scala版本可能还不够。

这应该有效。

addSbtPlugin("org.me" % "sbt-plugin_2.12_1.0" % "1.2.3")

如果你发现这个后缀_1.0来自哪里,修复scala版本会有所帮助:

addSbtPlugin("org.me" %% "sbt-plugin" % "1.2.3")

评论后更新

好的,谢谢,我不知道插件的工作方式不同。

但是尝试以不同的方式为解析器定义解析器(适用于我):

resolvers += "localtrix" at "file:///Users/jast/repo/localtrix"
addSbtPlugin("org.me" % "sbt-plugin" % "1.2.3")

答案 1 :(得分:1)

默认情况下,sbt插件是已发布的常春藤样式,因此当您引用本地存储库时,请使用Resolver.ivyStylePatterns。发布:

publishTo := Some(Resolver.file("localtrix", file("/Users/jast/repo/localtrix"))(Resolver.ivyStylePatterns))

要解决:

resolvers += Resolver.file("localtrix", file("/Users/jast/repo/localtrix"))(Resolver.ivyStylePatterns)
addSbtPlugin("org.me" % "sbt-plugin" % "1.2.3")

或者你可以为插件设置publishMavenStyle := true,但我发现你已经知道了。