Consider defining a custom task to download .scalafmt.conf
from remote repository
lazy val remoteScalafmtConfig = taskKey[Unit]("Fetch .scalafmt from external repository")
remoteScalafmtConfig := {
import scala.sys.process._
streams.value.log.info("Downloading .scalafmt.conf config from remote repository")
val remoteScalafmtFile = "https://some/external/repo/.scalafmt.conf"
val baseDir = (Compile / baseDirectory).value
url(s"$remoteScalafmtFile") #> (baseDir / ".scalafmt.conf") !
}
and then have compile
task depend on remoteProtoFiles
task like so
compile in Compile := (compile in Compile).dependsOn(remoteScalafmtConfig).value
Now executing sbt compile
should download .scalafmt.conf
into project's base directory before compilation executes.
We could create an sbt auto plugin to distribute to each project:
package example
import sbt._
import Keys._
object ScalafmtRemoteConfigPlugin extends AutoPlugin {
object autoImport {
lazy val remoteScalafmtConfig = taskKey[Unit]("Fetch .scalafmt from external repository")
}
import autoImport._
override lazy val projectSettings = Seq(
remoteScalafmtConfig := remoteScalafmtConfigImpl.value,
compile in Compile := (compile in Compile).dependsOn(remoteScalafmtConfig).value
)
lazy val remoteScalafmtConfigImpl = Def.task {
import scala.sys.process._
streams.value.log.info("Downloading .scalafmt config from remote repository...")
val remoteScalafmtFile = "https://github.com/guardian/tip/blob/master/.scalafmt.conf"
val baseDir = (Compile / baseDirectory).value
url(s"$remoteScalafmtFile") #> (baseDir / ".scalafmt.conf") !
}
}
Now importing the plugin in project/plugins.sbt
and enabling via enablePlugins(ScalafmtRemoteConfigPlugin)
would automatically download .scalafmt
after executing sbt compile
.