Can't add compile dependencies with sbt.AutoPlugins
I am trying to create a plugin that automatically sets a set of scalariform settings.
My plugin build.sbt:
name := "my-scalariform"
organization := "com.my"
version := "1.0-SNAPSHOT"
sbtPlugin := true
scalacOptions ++= Seq("-feature", "-deprecation", "-unchecked")
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0")
My initial plugin construction:
package com.my.plugins import com.typesafe.sbt.SbtScalariform import com.typesafe.sbt.SbtScalariform.{ ScalariformKeys, scalariformSettings } import sbt.AutoPlugin import sbt.{ Compile, Test } import sbt.Keys.{ compile, compileInputs } import scalariform.formatter.preferences.{ DoubleIndentClassDeclaration, FormattingPreferences, IndentSpaces, IndentWithTabs, PreserveDanglingCloseParenthesis } object MyScalariformPlugin extends AutoPlugin { override def trigger = allRequirements lazy val formattingPreferences = { import scalariform.formatter.preferences._ Seq( ScalariformKeys.preferences := FormattingPreferences() .setPreference(DoubleIndentClassDeclaration, true) .setPreference(IndentSpaces, 2) .setPreference(IndentWithTabs, false) .setPreference(PreserveDanglingCloseParenthesis, true) ) } override lazy val projectSettings = scalariformSettings ++ formattingPreferences }
When I added this plugin to my project, I see my scalar settings:
> scalariform-preferences
[info] FormattingPreferences(Map(DoubleIndentClassDeclaration -> true, IndentSpaces -> 2, IndentWithTabs -> false, PreserveDanglingCloseParenthesis -> true))
However, there is no scalar dependency in compileInputs:
> inspect compile:compile::compileInputs
...
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:792
[info] Dependencies:
[info] compile:compile::incCompileSetup
[info] compile:compile::streams
[info] compile:compile::dependencyClasspath
[info] compile:compile::compileOrder
[info] compile:compile::scalacOptions
[info] compile:compile::classDirectory
[info] compile:compile::javacOptions
[info] compile:compile::sourcePositionMappers
[info] compile:compile::compilers
[info] compile:compile::sources
[info] compile:compile::maxErrors
[info] Reverse dependencies:
[info] compile:compile
...
If I explicitly add the scalar command to override as a value in my plugin and then explicitly add it to my project, I get the correct dependencies:
lazy val commandSettings = Seq( compileInputs in (Compile, compile) <<= (compileInputs in (Compile, compile)) dependsOn (ScalariformKeys.format in Compile), compileInputs in (Test, compile) <<= (compileInputs in (Test, compile)) dependsOn (ScalariformKeys.format in Test) )
Dependencies:
> inspect compile:compile::compileInputs
...
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:792
[info] (com.my.plugins.MyScalariformPlugin) MyScalariformPlugin.scala:22
[info] Dependencies:
[info] compile:compile::incCompileSetup
[info] compile:compile::streams
[info] compile:compile::dependencyClasspath
[info] compile:scalariformFormat
[info] compile:compile::compileOrder
[info] compile:compile::scalacOptions
[info] compile:compile::classDirectory
[info] compile:compile::javacOptions
[info] compile:compile::sourcePositionMappers
[info] compile:compile::compilers
[info] compile:compile::sources
[info] compile:compile::maxErrors
[info] Reverse dependencies:
[info] compile:compile
...
I tried to define this dependency myself using autoImport, but this results in an error:
object autoImport { lazy val commandSettings = Seq( compileInputs in (Compile, compile) <<= (compileInputs in (Compile, compile)) dependsOn (ScalariformKeys.format in Compile), compileInputs in (Test, compile) <<= (compileInputs in (Test, compile)) dependsOn (ScalariformKeys.format in Test) ) } import autoImport._
Errors:
[error] References to undefined settings:
[error]
[error] */test:compile::compileInputs from */test:compile::compileInputs ((com.my.plugins.MyScalariformPlugin.autoImport) MyScalariformPlugin.scala:24)
[error] Did you mean test:compile::compileInputs ?
[error]
[error] */test:scalariformFormat from */test:compile::compileInputs ((com.my.plugins.MyScalariformPlugin.autoImport) MyScalariformPlugin.scala:24)
[error] Did you mean test:scalariformFormat ?
[error]
[error] */compile:compile::compileInputs from */compile:compile::compileInputs ((com.my.plugins.MyScalariformPlugin.autoImport) MyScalariformPlugin.scala:23)
[error] Did you mean compile:compile::compileInputs ?
[error]
[error] */compile:scalariformFormat from */compile:compile::compileInputs ((com.my.plugins.MyScalariformPlugin.autoImport) MyScalariformPlugin.scala:23)
[error] Did you mean compile:scalariformFormat ?
[error]
+3
source to share