我创建了一个可重现的示例,说明了我在使用SBT插件解析时遇到的问题:
https://github.com/NicolasRouquette/sbt.problem.example
此示例有两个SBT项目:
test.plugin
一个简单的SBT插件test.app
一个使用test.plugin
还有一个本地Maven存储库,test.plugin
发布了一个POM文件,其中包含如下属性:
<properties>
<git.branch>master</git.branch>
<git.commit>fe2dc11d6fbb85c5ce0e83b031bbd425997bbd59</git.commit>
<git.tags></git.tags>
</properties>
<properties>
<scalaVersion>2.10</scalaVersion>
<sbtVersion>0.13</sbtVersion>
<extraDependencyAttributes xml:space="preserve">+e:sbtVersion:#@#:+0.13:#@#:+module:#@#:+sbt-license plugin:#@#:+e:scalaVersion:#@#:+2.10:#@#:+organisation:#@#:+com.banno:#@#:+branch:#@#:+@#:NULL:#@:#@#:+revision:#@#:+0.1.5:#@#:
+e:sbtVersion:#@#:+0.13:#@#:+module:#@#:+sbt-license-report:#@#:+e:scalaVersion:#@#:+2.10:#@#:+organisation:#@#:+com.typesafe.sbt:#@#:+branch:#@#:+@#:NULL:#@:#@#:+revision:#@#:+1.0.0:#@#:
+e:sbtVersion:#@#:+0.13:#@#:+module:#@#:+sbt-git:#@#:+e:scalaVersion:#@#:+2.10:#@#:+organisation:#@#:+com.typesafe.sbt:#@#:+branch:#@#:+@#:NULL:#@:#@#:+revision:#@#:+0.8.5:#@#:
+e:sbtVersion:#@#:+0.13:#@#:+module:#@#:+aether-deploy:#@#:+e:scalaVersion:#@#:+2.10:#@#:+organisation:#@#:+no.arktekk.sbt:#@#:+branch:#@#:+@#:NULL:#@:#@#:+revision:#@#:+0.16:#@#:
</extraDependencyAttributes>
</properties>
我无法在test.app
上运行SBT,因为SBT无法解析test.plugin
:
addSbtPlugin("org.test" % "test-plugin" % "1.0")
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.test#test-plugin;1.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] org.test:test-plugin:1.0 (sbtVersion=0.13, scalaVersion=2.10)
[warn]
[warn] Note: Unresolved dependencies path:
[warn] org.test:test-plugin:1.0 (sbtVersion=0.13, scalaVersion=2.10) (/opt/local/imce/users/nfr/github.imce/example/test.app/project/plugins.sbt#L6-7)
[warn] +- default:test-app-build:0.1-SNAPSHOT (sbtVersion=0.13, scalaVersion=2.10)
sbt.ResolveException: unresolved dependency: org.test#test-plugin;1.0: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:294)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:191)
at sbt.IvyActions$$anonfun$updateEither$1.apply(IvyActions.scala:168)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:155)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:132)
at sbt.IvySbt.sbt$IvySbt$$action$1(Ivy.scala:57)
...
基于试图了解调试器发生了什么,我得到的印象是:
有人可以确认/更正我的分析吗?
有没有办法让这个maven发布的插件依赖项查找工作?
答案 0 :(得分:2)
感谢repro项目。
第一个问题是你有两个<properties>
元素。 sbt将使用URL布局和POM的内容来解析插件。以下是合并<properties>
元素的方法。不确定是否有更优雅的方式:
makePom := {
val old = makePom.value
val pom = xml.XML.loadFile(old)
val additionalProperties =
(<git.branch>{git.gitCurrentBranch.value}</git.branch>
<git.commit>{git.gitHeadCommit.value.getOrElse("N/A")+(if (git.gitUncommittedChanges.value) "-SNAPSHOT" else "")}</git.commit>
<git.tags>{git.gitCurrentTags.value}</git.tags>)
val newPom = pom.copy(child = pom.child.toSeq map {
case elem: xml.Elem if elem.label == "properties" =>
elem.copy(child = elem.child ++ additionalProperties)
case x => x
})
xml.XML.save(old.toString, newPom, enc = "UTF-8", xmlDecl = true)
old
}
接下来,当您尝试解析插件时,您应该会看到类似的内容:
[warn] ==== Local Test: tried
[warn] file:/xxx/sbt.problem.example/test.app/project/../local.repo/org/test/test-plugin_2.10_0.13/1.0/test-plugin-1.0.pom
看到test.app/project/../local.repo/
成为test.app/local.repo
。而不是&#34; ..&#34;这是您在test.app/project/plugins.sbt
中可以做的事情:
resolvers += new MavenCache("Local Test", baseDirectory.value.getParentFile.getParentFile / "local.repo")
addSbtPlugin("org.test" % "test-plugin" % "1.0")