sbt 2.0 の変更点
互換性に影響のある変更点
See also Migrating from sbt 1.x.
- Scala 3 を用いたメタビルド。ビルド定義やプラグインに使われる sbt 2.x build.sbt DSL は Scala 3.x ベースとなった (現行では 3.7.2) (sbt 1.x 並びに 2.x は、Scala 2.x と 3.x の両方をビルドすることが可能) by @eed3si9n, @adpi2, and others.
- コモン・セッティング。build.sbt に直書きされたセッティングは、ルートサブプロジェクトだけではなく、全てのサブプロジェクトに追加され、これまで
ThisBuild
が受け持ってきた役目を果たすことができる。 - 差分テスト。
test
は、テスト結果をキャッシュする差分テストへと変更された。全テストを走らせたい場合はtestFull
を使う by @eed3si9n in #7686 - キャッシュ化されたタスク。全てのタスクはデフォルトで、キャッシュ化されている。詳細はキャッシュ参照。
- Depedency tree.
dependencyTree
tasks are unified to one input task by @eed3si9n in #8199 test
タスクの形がUnit
からTestResult
へと変更された by @eed3si9n in #8181- 以前
URL
に型付けされていたデフォルトのセッティングやタスクキー (apiMappings
,apiURL
,homepage
,organizationHomepage
,releaseNotesURL
など) はURI
に変更された in #7927 license
キーの型がSeq[(String, URL)]
からSeq[License]
へと変更された in #7927- sbt 2.x プラグインは
_sbt2_3
という suffix を用いて公開される by @eed3si9n in #7671 - sbt 2.x は、
platform
セッティングを追加して、ModuleID
の%%%
演算子を使わなくても、%%
演算子だけで JVM、JS、Native のクロスビルドができるようにした by @eed3si9n in #6746 useCoursier
セッティングを廃止して、Coursier をオプトアウトできないようにした by @eed3si9n in #7712Key.Classpath
is changed to be an alias of theSeq[Attributed[xsbti.HashedVirtualFileRef]]
type, instead ofSeq[Attributed[File]]
. Similarly, some task keys that used to returnFile
have changed to returnHashedVirtualFileRef
instead. See Caching Files.- In sbt 2.x
target
defaults totarget/out/jvm/scala-3.7.2/<subproject>/
, as opposed to<subproject>/target/
.
勧告どおり廃止された機能
Features
- Project matrix. Project matrix, which was available via plugin in sbt 1.x, is in-sourced to provide parallel cross build support.
- sbt query. sbt 2.x extends the unified slash syntax to support query of subprojects. Details below.
- Local/remote cache system. Details below
- Client-side run. Details below.
Common settings
In sbt 2.x, the bare settings in build.sbt
are interpreted to be common settings, and are injected to all subprojects. This means we can now set scalaVersion
without using ThisBuild
scoping:
scalaVersion := "3.7.2"
This also fixes the so-called dynamic dispatch problem:
lazy val hi = taskKey[String]("")
hi := name.value + "!"
In sbt 1.x hi
task will capture the name of the root project, but in sbt 2.x it will return the name
of each subproject with !
:
$ sbt show hi
[info] entering *experimental* thin client - BEEP WHIRR
[info] terminate the server with `shutdown`
> show hi
[info] foo / hi
[info] foo!
[info] hi
[info] root!
Contributed by @eed3si9n in #6746
sbt query
To filter down the subprojects, sbt 2.x introduces sbt query.
$ sbt foo.../test
The above runs all subprojects that begins with foo
.
$ sbt ...@scalaBinaryVersion=3/test
The above runs all subprojects whose scalaBinaryVersion
is 3
. Contributed by @eed3si9n in #7699
Incremental test
In sbt 2.x, test
task became an input task that accept arguments that can filter the test suites to run:
> test *Example*
In addition, test
is incremental and cached. This means, the test will not run unless it previously failed or something changed since the last run.
See test for details.
Local/remote cache system
sbt 2.x implements cached task by default, which can automatically cache the task results to local disk and Bazel-compatible remote cache.
lazy val task1 = taskKey[String]("doc for task1")
task1 := name.value + version.value + "!"
This tracks the inputs into the task1
and creates a machine-wide disk cache, which can also be configured to also use a remote cache. Since it's common for sbt tasks to also produce files on the side, we also provide a mechanism to cache file contents:
lazy val task1 = taskKey[String]("doc for task1")
task1 := {
val converter = fileConverter.value
....
val output = converter.toVirtualFile(somefile)
Def.declareOutput(output)
name.value + version.value + "!"
}
See Caching for details. Contributed by @eed3si9n in #7464 / #7525.
Client-side run
The sbt runner 1.10.10 and later script defaults to using sbtn (GraalVM native-image client) for sbt 2.x. In sbt 2.0, sbt server sends the run
task back to sbtn, which will fork a fresh JVM. All you have to do is:
sbt run
This avoids blocking the sbt server, and you can have multiple runs. Contributed by @eed3si9n in #8060. See also run documentation.
Performance improvements
Adrien Piquerez contributed a series of changes to improve performance while he was at Scala Center.
- perf: Reduces number of long-living instances to speed up startup by 20% relative to 2.0.0-M2 by @adpi2 in #7866
- perf: Reduces creation of
Setting
andInitialize
by @adpi2 in #7880 - perf: Refactors
Settings
and optimize indexing of aggregate keys by @adpi2 in #7879 - perf: Removes instances of
Info
andBasicAttributeMap
by @adpi2 in #7882
Previously on sbt
See also: