Search code examples
sbtsbt-plugin

Sbt doesn't enable some custom plugins


I've written autoPlugin like so

object ThriftIfaceSbt extends AutoPlugin {

  override def projectSettings = {
    Seq(
      crossVersion := {
        println(s"Init ThriftIfaceSbt ${name.value}")
        CrossVersion.Disabled
      },
      autoScalaLibrary := false,
      resourceDirectories in Compile += baseDirectory.value / "src" / "main" / "thrift"
    )
  }

}

Then i publishLocal and try it in my build.sbt

lazy val myProject = (project in file("a")).enablePlugins(ThriftIfaceSbt)

That plugin doesn't get applied to project.. i don't understand why.

It it possible that SBT silently ignores my plugin?


Solution

  • One likely reason that it's not working is because you're overriding settings provided by the sbt JvmPlugin, but you don't declare a dependency on it, so the order that they get applied is undefined. If your plugin gets applied first, then the JvmPlugin settings will override whatever your plugin has configured.

    You need to add:

    override def requires = sbt.plugins.JvmPlugin
    

    to your plugin. Even if this doesn't fix your issue, you'll still need to add that.