scaladependenciesscala.jssbt-plugin

SBT Plugin Where is %%% defined?


I have an SBT plugin which will auto-generate some Scala.js code just before compile time. This code depends on a library which I would like to automatically include when the plugin is enabled.

This compiles and runs, but does not get the Scala.js version of the library:

import sbt._
import Keys.libraryDependencies

object MyPlugin extends AutoPlugin {
  object autoImport {
    lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
      libraryDependencies += "my.lib" %% "library" % "0.1.0"
    )
  }

  import autoImport._

  override lazy val projectSettings = baseSettings
}

I when I try to use "my.lib" %%% "library" % "0.1.0", I get:

value %%% is not a member of String

I feel like I'm probably missing an import, but I can't find where this is supposed to be defined.


Solution

  • %%% is defined by the sbt-platformdeps plugin.

    Unless your sbt plugin already depends on sbt-scalajs, you'll need to add a dependency to it in your plugin project's settings:

    addSbtPlugin("org.portable-scala" % "sbt-platform-deps" % "1.0.0")
    

    The following import will bring it in scope:

    import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport._