1

I am writing a Plugin for SBT that will generate the configuration files needed to create an Azure Function from a Scala program. My efforts are on github (https://github.com/code-star/sbt-azure-functions-plugin/tree/develop), and as can be read in the readme, I want to automatically trigger the assembly task whenever the user issues sbt azfunCreateZipFile.

Users of my plugin, can be achieve this by adding the following line to their build.sbt:

azfunCreateZipFile := (azfunCreateZipFile dependsOn assembly).value

I would like that task wiring to be already included in my plugin definition. How can I do this?

I know Tasks can be made dependent on other Tasks by using otherTask.value in the task definition, so I tried adding such a line to the azfunCreateZipFile task definition (see ./plugin/src/main/scala/sbtazurefunctions/AzureFunctions.scala):

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

But then I get an error that assembly is not found:

[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> 

I have tried many imports, but none were successful:

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

What can I do to fix this?

JeanMarc
  • 306
  • 1
  • 10

1 Answers1

1

This other SO answer (How can I use an sbt plugin as a dependency in a multi-project build?) finally put me on the right track, as it shows the use of libraryDependencies += Defaults.sbtPluginExtra, so thanks @michael-zajac.

I ended up adding the assembly dependency like this:

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")
    ),
    ...

Even better:

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