2015-12-30 39 views
1

我创建了一个问题重复的例子的SBT插件我与SBT插件分辨率经历:无法解析发布到一个Maven回购

https://github.com/NicolasRouquette/sbt.problem.example

这个例子有两个SBT项目:

  • test.plugin简单SBT插件
  • test.app使用了test.plugin
  • 一个简单的SBT项目0

也有到该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:#@#:[email protected]#:NULL:#@:#@#:+revision:#@#:+0.1.5:#@#: 
    +e:sbtVersion:#@#:+0.13:#@#:+module:#@#:+sbt-license-report:#@#:+e:scalaVersion:#@#:+2.10:#@#:+organisation:#@#:+com.typesafe.sbt:#@#:+branch:#@#:[email protected]#:NULL:#@:#@#:+revision:#@#:+1.0.0:#@#: 
    +e:sbtVersion:#@#:+0.13:#@#:+module:#@#:+sbt-git:#@#:+e:scalaVersion:#@#:+2.10:#@#:+organisation:#@#:+com.typesafe.sbt:#@#:+branch:#@#:[email protected]#:NULL:#@:#@#:+revision:#@#:+0.8.5:#@#: 
    +e:sbtVersion:#@#:+0.13:#@#:+module:#@#:+aether-deploy:#@#:+e:scalaVersion:#@#:+2.10:#@#:+organisation:#@#:+no.arktekk.sbt:#@#:+branch:#@#:[email protected]#: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) 
... 

基于试图了解发生了什么事情与调试,我得到的印象是:

  • 运行SBT时解析插件很早就发生了;这意味着它涉及很多SBT/Ivy机器
  • 我不太明白SBT/Ivy机器如何解决发布到Maven存储库的SBT插件(尽管我在某处看到某种Maven/Ivy转换)
  • 似乎Maven的POM性质,不分析检索sbtVersion(如0.13)和scalaBinaryVersion(如2.10)的工件

的有人能确认/纠正我的分析?

有没有办法让这个Maven发布的插件依赖查找工作?

回答

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。而不是“..”这里是你可以做什么在test.app/project/plugins.sbt

resolvers += new MavenCache("Local Test", baseDirectory.value.getParentFile.getParentFile/"local.repo") 

addSbtPlugin("org.test" % "test-plugin" % "1.0") 
+0

谢谢@EugeneYokota,这解决了我的问题! –

+0

至于合并POM中的属性,我使用pomPostProcess改进了解决方案,请参见[https://github.com/NicolasRouquette/sbt.problem.example/blob/master/test.plugin/build.sbt#L51] –

相关问题