2015-12-30 72 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] –

相關問題