1. 起動時にアクションを実行する方法

起動時にアクションを実行する方法 

グローバル設定 onLoadState => State 型で、すべてのプロジェクトがビルドされロードされた後に一度だけ実行されます。プロジェクトがアンロードされるときの同様のフックとして onUnload があります。

プロジェクトのアンロードは通常、reload コマンドまたは set コマンドの結果として発生します。onLoad および onUnload フックはグローバルであるため、この設定の変更には通常、以前の値で新しい関数を構成することが含まれます。次の例は、onLoad を定義する基本的な構造を示しています。

起動時に dependencyUpdates という名前のタスクを実行するとします。これはあなたができることです。

lazy val dependencyUpdates = taskKey[Unit]("foo")

// This prepends the String you would type into the shell
lazy val startupTransition: State => State = { s: State =>
  "dependencyUpdates" :: s
}

lazy val root = (project in file("."))
  .settings(
    ThisBuild / scalaVersion := "2.12.6",
    ThisBuild / organization := "com.example",
    name := "helloworld",
    dependencyUpdates := { println("hi") },

    // onLoad is scoped to Global because there's only one.
    Global / onLoad := {
      val old = (Global / onLoad).value
      // compose the new transition on top of the existing one
      // in case your plugins are using this hook.
      startupTransition compose old
    }
  )

この手法を使用すると、起動時のサブプロジェクトも切り替えることができます。