sbt, the interactive build tool
Go to file
Rikito Taniguchi e292d05322
[2.x] Fix Scala 3 .previous expansion for unstable path (#9041)
**problem**
.previous was implemented as an inline expansion to wrapInitTask(Previous.runtime(in)(<instance of JsonFormat[A1]))

For example, the .previous on taskKey[String] gets inlined like
this, and then sbt's macro moves `Previous.runtime(...)(using StringJsonFormat)` into task input.

lazy val fingerprints = taskKey[String]("...")
val previousFingerprints = fingerprints.previous

// inlined
val previousFingerprints: Option[String] = {
  InputWrapper.wrapInitTask(
    Previous.runtime(...)(using StringJsonFormat)
  )
}

- 6c8ee6ea37/main-settings/src/main/scala/sbt/Def.scala (L410-L412)
- 6c8ee6ea37/core-macros/src/main/scala/sbt/internal/util/appmacro/Cont.scala (L468)

However, if the return type of task is a bit more complicated like
Seq[String], it doesn't work:

Scala 3 Compiler's inliner creates a synthetic proxy symbol if the
inlining tree is an application, whose arguments are unstable path.

For example,

lazy val fingerprints = taskKey[Seq[String]]("...")
val previousFingerprints = fingerprints.previous

// inline to
val previousFingerprints: Option[Seq[String]] = {
  val x$2$proxy1 = immSeqFormat(StringJsonFormat)
  InputWrapper.wrapInitTask(
    Previous.runtime(...)(using x$2$proxy1)
  )
}

cc7d6db700/compiler/src/dotty/tools/dotc/inlines/Inliner.scala (L324-L329)

However, sbt2's Cont macro captures only `Previous.runtime(...)(using x$2$proxy1)`, while it doesn't capture the proxy definition. Consequently, while sbt macro moves the `Previous.runtime(...)` application as a task input, the proxy definition is left in the task body.

mapN(
  (
    link / fingerprints,
    Previous.runtime(...)(using x$2$proxy1) // here x$2$proxy1 can't be found
  )
) {
  ...
  val x$2$proxy1 = ...
}

Then we get:

-- Error: /.../build.sbt:14:59
14 |  val previousFingerprints = (link / fingerprints).previous
   |                                                           ^
   |While expanding a macro, a reference to value x$2$proxy1 was used outside the scope where it was defined

**How this PR fixed**
This commit fixes the problem by defining a dedicated Scala3 macro for .previous that summon JsonFormat[A1] inside the macro before constructing the wrapped previous.runtime(...)(using ...) by inliner. The macro insert the found given value tree directly into the previous.runtime(...)(using $found).

This way, Cont macro always moves the Previous.runtime tree along with it's given argument, without leaking compiler-generated inline proxies across scopes.
2026-04-07 22:45:01 -04:00
.github Fix old shell syntax warning (#8998) 2026-03-31 01:05:16 -04:00
buildfile/src Add parentheses (#9000) 2026-03-31 13:48:59 -04:00
client Revert "[2.x] feat: Enable musl static linking for sbtn on JDK 17+ (#8464)" (#8557) 2026-01-16 00:06:28 -05:00
contributing-docs [2.x] Scala 3.8.3 (#8997) 2026-04-05 14:28:47 -04:00
core-macros/src [2.x] Remove Path type from caching (#9032) 2026-04-06 14:40:33 -04:00
internal [2.x] Replace defunct link (#8950) 2026-03-21 14:23:26 -04:00
launch [2.x] feat: repositories_force support (#8761) 2026-02-20 01:52:59 -05:00
launcher-package [2.x] Update sbt version in launcher-package test (#9021) 2026-04-05 19:26:05 -04:00
licenses move remaining pieces of sbt subproject to sbt_pending and fix notices 2010-09-21 21:55:50 -04:00
lm-core [2.x] fix: Resolve relative paths from -sbt-dir / sbt.global.base (#9001) 2026-04-05 19:27:34 -04:00
lm-coursier [2.x] Prefer local ScalaModuleInfo over global config (#9028) 2026-04-05 18:41:30 -04:00
lm-ivy/src [2.x] Update ErrorMessageAuthenticator. Remove unnecessary reflection (#8976) 2026-03-24 23:59:50 -04:00
main [2.x] Remove Path type from caching (#9032) 2026-04-06 14:40:33 -04:00
main-actions/src Add parentheses (#9000) 2026-03-31 13:48:59 -04:00
main-command/src [2.x] feat: Add cacheVersion setting for global cache invalidation (#8993) 2026-04-01 11:23:10 +09:00
main-settings/src [2.x] Fix Scala 3 .previous expansion for unstable path (#9041) 2026-04-07 22:45:01 -04:00
notes [2.x] feat: Add cacheVersion setting for global cache invalidation (#8993) 2026-04-01 11:23:10 +09:00
project [2.x] Scala 3.8.3 (#8997) 2026-04-05 14:28:47 -04:00
protocol/src Add parentheses (#9000) 2026-03-31 13:48:59 -04:00
run [2.x] fix: Fixes double quotes handling in fork mode (#8765) 2026-02-24 23:22:48 -05:00
sbt-app/src Enable project-matrix/native test (#9038) 2026-04-07 08:15:43 -04:00
sbt-ivy/src/main/scala/sbt Remove unnecessary reflection in IvyXml (#9024) 2026-04-05 13:13:32 -04:00
sbt-remote-cache/src/main/scala/sbt remove unnecessary `case` 2025-02-22 08:48:29 +09:00
sbtw fix: Use sbt script in BSP config instead of hardcoded Java path (#8920) 2026-03-19 20:57:53 -04:00
scripted-sbt Add parentheses (#9000) 2026-03-31 13:48:59 -04:00
scripts Fix lm-coursier scripted 2024-10-11 14:30:55 +02:00
server-test/src [2.x] Scala 3.8.3 (#8997) 2026-04-05 14:28:47 -04:00
src [2.x] Add scripted test for #7838 (#8541) 2026-01-20 12:13:27 -05:00
tasks Use enum instead of scala.Enumeration in sbt.Execute.State (#8788) 2026-02-22 22:21:29 -05:00
tasks-standard Add parentheses (#9000) 2026-03-31 13:48:59 -04:00
testing [2.x] fix: Fixes testing EventHandler race condition 2026-02-09 10:55:06 -05:00
util-cache [2.x] feat: Add cacheVersion setting for global cache invalidation (#8993) 2026-04-01 11:23:10 +09:00
util-collection [2.x] refactor: Fix warning in Settings.scala (#8999) 2026-03-31 02:00:15 -04:00
util-tracking [2.x] test: Migrate TrackedSpec.scala to verify.BasicTestSuite (#8547) 2026-01-15 22:51:29 -05:00
worker/src [2.x] ci: Update java file formatter plugin (#8892) 2026-03-10 11:19:48 -04:00
zinc-lm-integration/src [2.x] test: Update ZincComponentCompilerSpec (#8979) 2026-03-25 01:18:14 -04:00
.git-blame-ignore-revs [2.x] blame ignore commits (#8814) 2026-02-25 10:51:21 -05:00
.gitattributes Fix line endings in msi 2021-11-19 20:41:39 -05:00
.gitignore [2.x] fix : BSP compile returns StatusCode.Error on failure (#8104) (#8709) 2026-02-07 11:01:49 -05:00
.gitmodules Move metadata to lm-coursier/metadata 2024-10-09 09:44:42 +02:00
.java-version Scala 3.8.0 2026-01-24 04:52:28 -05:00
.jvmopts Add .jvmopts 2023-11-25 01:06:30 -05:00
.mailmap Add mailmap 2019-06-11 09:30:14 +02:00
.sbtopts Restore .sbtopts file 2020-11-19 12:42:26 -08:00
.scala-steward.conf Pin slf4j-api 2023-01-02 22:06:46 -05:00
.scalafix.conf [2.x] ci: Add scalafix DisableSyntax.noReturns (#8922) 2026-03-19 10:48:10 -04:00
.scalafmt.conf Add scalafmt newlines.topLevelStatementBlankLines setting (#8949) 2026-03-21 02:58:49 -04:00
AGENTS.md [2.x] fix: Fix spelling and link in AGENTS docs (#8837) 2026-03-01 00:25:09 -05:00
CONTRIBUTING.md [2.x] fix: Fix typo in CONTRIBUTING guide 2026-02-28 20:44:19 -06:00
LICENSE Transfer copyright to Scala Center 2023-06-20 16:39:07 +02:00
NOTICE Transfer copyright to Scala Center 2023-06-20 16:39:07 +02:00
PROFILING.md docs: Update flamegraph guide --lines 2025-11-09 18:06:13 -05:00
README.md [2.x] docs: Move to CONTRIBUTING (#8629) 2026-01-25 15:48:09 -05:00
SUPPORT.md Transfer copyright to Scala Center 2023-06-20 16:39:07 +02:00
build.sbt Update mima setting (#9039) 2026-04-07 17:54:53 -04:00
sbt fix: Use sbt script in BSP config instead of hardcoded Java path (#8920) 2026-03-19 20:57:53 -04:00
sbt-allsources.sh Merge remote-tracking branch 'lm/wip/sbt-2.x' into 2.x-lm-coursier 2024-10-09 08:50:03 +02:00
sbt.sh Implement sbt-launch.jar download 2021-04-19 23:43:15 -04:00
server.md setting query is "sbt/setting" 2017-10-03 01:45:06 -04:00

README.md

CI Latest version Discord

sbt

sbt is a build tool for Scala, Java, and more.

For general documentation, see https://www.scala-sbt.org/.

sbt 2.x

This is the 2.x series of sbt. The source code of sbt is split across several GitHub repositories, including this one.

  • sbt/io hosts sbt.io module.
  • sbt/zinc hosts Zinc, an incremental compiler for Scala.
  • sbt/sbt, this repository hosts modules that implement the build tool.
  • Setup: Describes getting started with the latest binary release.
  • FAQ: Explains how to get help and more.
  • sbt/sbt-zero-seven: hosts sbt 0.7.7 and earlier versions

Issues and Pull Requests

Please read CONTRIBUTING carefully before opening a GitHub Issue or a pull request.

If you're looking for an idea for a contribution, issues labeled with good first issue or help wanted might be good starting points.

If you would like to ask questions about sbt, there's sbt channel on Scala Discord, but it would be good to gather questions on Stackoverflow.

license

See LICENSE.