簡體   English   中英

如何將任務依賴項從另一個插件添加到我的 SBT 插件?

[英]How can I add a Task dependency on a task from another plugin to my SBT plugin?

我正在為 SBT 編寫一個插件,它將生成從 Z3012DCFF14577EBBDAB876DABB8776DABB8776DABB877E1 的 Azure Function Function 所需的配置文件我的努力是在 github ( https://github.com/code-star/sbt-azure-functions-plugin/tree/develop )上,並且可以在自述文件中閱讀,我想在任何時候自動觸發assembly任務用戶發出sbt azfunCreateZipFile

我的插件的用戶可以通過在他們的build.sbt中添加以下行來實現這一點:

azfunCreateZipFile := (azfunCreateZipFile dependsOn assembly).value

我希望該任務接線已經包含在我的插件定義中。 我怎樣才能做到這一點?

我知道可以通過在任務定義中使用otherTask.value使任務依賴於其他任務,因此我嘗試在azfunCreateZipFile任務定義中添加這樣一行(請參閱./plugin/src/main/scala/sbtazurefunctions/AzureFunctions.scala ) :

azfunGenerateFunctionJsons := {
  // depend on assembly step
  val _ = assembly.value
  ... <actual task definition code>
  azfunTargetFolder.value
}

但是后來我收到一個錯誤,即找不到程序集:

[IJ]sbt:root> compile
[info] Compiling 1 Scala source to /home/jml/work/scala/azure/sbt-azure-functions- plugin/plugin/target/scala-2.12/sbt-1.0/classes ...
[error] /home/jml/work/scala/azure/sbt-azure-functions-plugin/plugin/src/main/scala/sbtazurefunctions/AzureFunctions.scala:113:15: not found: value assembly
[error]       val _ = assembly.value
[error]               ^
[error] one error found
[error] (plugin / Compile / compileIncremental) Compilation failed
[error] Total time: 1 s, completed Jan 3, 2021, 4:41:56 PM
[IJ]sbt:root> 

我嘗試了很多導入,但沒有一個成功:

import sbtassembly.AssemblyPlugin._ (and variations using AssemblyKeys and the AutoImport object)
import sbt.Keys._

我能做些什么來解決這個問題?

這個其他 SO 答案( 如何在多項目構建中使用 sbt 插件作為依賴項? )終於讓我走上了正確的軌道,因為它顯示了libraryDependencies += Defaults.sbtPluginExtra的使用,所以感謝@michael-zajac .

我最終添加了這樣的程序集依賴項:

lazy val plugin = (project in file("plugin"))
  .enablePlugins(SbtPlugin)
  .settings(
    ...<other settings>...,
    libraryDependencies ++= Seq(
      "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value,
      Defaults.sbtPluginExtra("com.eed3si9n" % "sbt-assembly" % "0.14.10", "1.0", "2.12")
    ),
    ...

更好的是:

    libraryDependencies ++= Seq(
      "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
    ),
    addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10"),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM