Commit Graph

3910 Commits

Author SHA1 Message Date
eugene yokota 6c8ee6ea37
[2.x] Remove Path type from caching (#9032)
**Problem**
Like File, Path normally captures the absolute path,
so likely not a good candidate for caching.

**Solution**
Ban it.

---------

Co-authored-by: Anatolii Kmetiuk <anatoliikmt@proton.me>
2026-04-06 14:40:33 -04:00
BrianHotopp 3890cc7086
[2.x] fix: Resolve relative paths from -sbt-dir / sbt.global.base (#9001)
getFileProperty returned relative File objects when system properties
like sbt.global.base were set to relative paths (e.g. via -sbt-dir
../cache in .sbtopts). This caused an assertion failure in
IO.directoryURI: "Not absolute: ../cache/plugins".

Also fixes misleading scaladoc in SemanticSelector that claimed
`<=1.0` is equivalent to `<1.1.0` — they differ for pre-release
versions like 1.1.0-M1 (#4423).

Fixes #3729

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 19:27:34 -04:00
corevibe555 606bb3b59c
[2.x] Fix: strip pipelining scalacOptions before launching the REPL (#8986)
**Problem**
When usePipelining := true in a multi-project build, sbt appends  
-Ypickle-java and -Ypickle-write <path>/early.jar to scalacOptions 
for fast parallel compilation. These flags were being leaked into the Scala  
REPL, causing failure on console

**Solution**
Strip pipelining flags before forwarding to the REPL  in Deafults.scala.
2026-04-05 13:47:36 -04:00
eugene yokota 5ad9abac2f
[2.x] fix: Fixes metabuild reloading (#9019)
**Problem**
There seems to be multiple problems around metabuild reloading (reload plugins).

1. Originally reported issue 9006 states that the build can't come back
   from reload plugins.
2. During the course of fixing, I discovered that when reload plugins is used
   the project name is set to "project" instead of foo-build etc.
3. Also there was a bug in the rootPaths when reload plugins is used,
   which results in class not defined error.

**Solution**
1. Fix the plugin context so reload plugin still behaves like a metabuild.
2. Fix the rootPaths.
2026-04-05 03:13:23 -04:00
eugene yokota 90770b6ad1
[2.x] fix: Fixes pollInterval (#9020)
**Problem/Solution**
checkBuildSources / pollInterval should just fallback to some value.
2026-04-05 00:52:29 -04:00
BitCompass 1f2d14aa3e
[2.x] fix: derivedProjects not invoked when no explicit root project is defined (#9012)
**Problem**
When build.sbt contains no explicit project definition (e.g. just bare settings with no lazy val root = project.in(file("."))), sbt creates a synthetic root project. In Load.loadTransitive, this synthetic root was processed with expand = false, which prevented AutoPlugin.derivedProjects from being called.
Any plugin relying on derivedProjects to inject projects would fail with "Reference to undefined setting" errors.

The workaround was to add an explicit root project in build.sbt (val root = project.in(file("."))), which caused the Some(root) branch to execute with expand = true.

**Solution**

Removed the expand variable from loadTransitive and pass true directly to processProject. Previously, the Some(root) branch set expand = true while the None branch set expand = false. Since derivedProjects should always be invoked for the root project regardless of whether it was explicitly defined or auto-generated, both branches should behave the same way. Eliminating the variable makes this intent clear.
2026-04-04 14:55:42 -04:00
corevibe555 4d71c15e87
[2.x] fix: resolve virtual path in -Ypickle-write scalac option (#9011)
earlyOutput is a virtual file reference, so passing it directly via
.toString produces a virtual path that scalac cannot resolve. Use
fileConverter.value.toPath() to convert it to an actual filesystem path.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 23:13:16 -04:00
Dream 544f56695a
[2.x] feat: Add cacheVersion setting for global cache invalidation (#8993)
* [2.x] feat: Add cacheVersion setting for global cache invalidation

**Problem**
There was no escape hatch to invalidate all task caches when needed.

**Solution**
Add `Global / cacheVersion` setting that incorporates into the cache key
hash. Changing it invalidates all caches. Defaults to reading system
property `sbt.cacheversion`, or else 0L. When 0L, the hash is identical
to the previous behavior (backward compatible).

Fixes #8992

* [2.x] refactor: Simplify BuildWideCacheConfiguration and add cacheVersion test

- Replace auxiliary constructors with default parameter values
- Add unit test verifying cacheVersion invalidates the cache

* [2.x] fix: Restore auxiliary constructors for binary compatibility

* [2.x] test: Improve cacheVersion scripted test and add release note

- Scripted test now verifies cache invalidation via a counter
  that increments only when the task body actually executes
- Add release note documenting the cacheVersion setting
2026-04-01 11:23:10 +09:00
kenji yoshida 6d44aca9b1
Add parentheses (#9000) 2026-03-31 13:48:59 -04:00
BrianHotopp 4f06b90534
[2.x] fix: Write maven-metadata-local.xml during publishM2 for SNAPSHOTs (#8996)
publishM2 never wrote maven-metadata-local.xml, which Maven uses to
distinguish local installs from remote artifacts. Without it, Maven
re-downloads remote SNAPSHOTs even when a local copy exists, making
publishM2 effectively broken for SNAPSHOT workflows.

Fixes #2053

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 01:58:57 -04:00
BrianHotopp 5697f074c1
[2.x] fix: Update ++ help text to reflect SemanticSelector matching (#8995)
The first paragraph of `help ++` still said "binary compatible" from
before PR #6946 changed the behavior to use SemanticSelector pattern
matching. Update it to match the already-correct second paragraph.

Fixes #6988

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 01:50:45 -04:00
Dream 3dd7f939cf
[2.x] fix: Scope dependencyMode filtering to compilation only (#8990)
**Problem**
When dependencyMode := Direct is set, the filtering was applied at
the managedClasspath level, which removed transitive dependencies
from all downstream classpaths including Test / dependencyClasspath.
This caused runtime test failures because transitive deps like
hamcrest-core (pulled in by junit) were missing.

**Solution**
Move the dependencyMode filtering from managedClasspath to a new
filteredDependencyClasspath task, and wire dependencyPicklePath
(the classpath used by the compiler) to use it. Runtime classpaths
like dependencyClasspath and fullClasspath remain unfiltered,
preserving all transitive dependencies for test execution.

Fixes #8989
2026-03-29 23:13:06 -04:00
Dream 9a48ed818f
[2.x] fix: Preserve configuration visibility in ivy.xml when publishing with coursier (#8988)
**Problem**
When publishing with coursier, the `visibility` attribute of `<conf />`
elements in `ivy.xml` was hardcoded to `"public"`. Configurations
defined as hidden (e.g. `scala-tool`) were incorrectly published with
`visibility="public"` instead of `"private"`.

The root cause was that `Inputs.configExtendsSeq` only extracted config
names and extends relationships, discarding the `isPublic` flag from
sbt's `Configuration` objects.

**Solution**
Add a `privateConfigNames: Set[String]` field to the lmcoursier
`Project` data class (with `@since` for backward compatibility).
Populate it from `Configuration.isPublic` in `CoursierInputsTasks`,
and use it in both `IvyXml` implementations to set the correct
visibility attribute.

Fixes sbt/sbt#5455
2026-03-29 00:37:00 -04:00
BitToby f81a1524bb
[2.x] fix: Stabilize progress indicator sort (#8984)
When multiple tasks run in parallel, the super shell progress lines reorder in a semi-random manner on every refresh because they are sorted by raw elapsed microseconds. Tasks that start at nearly the same time constantly swap positions due to sub-second timing jitter, making the display hard to read.

This fixes the sort key to use elapsed seconds (rounded down) with task name as a tiebreaker, matching the granularity already shown to the user (e.g. 3s). Tasks displaying the same elapsed second now stay alphabetically stable instead of flickering.
2026-03-26 18:17:30 -04:00
BitToby 99471da5f1
[2.x] fix: Fix ProjectMatrix base directory resolution for source dependencies (#8983)
**Problem**

ProjectMatrix.baseSettings computes sourceDirectory and unmanagedBase using base.getAbsoluteFile, which resolves relative paths against the JVM's working directory. This works fine within a single build, but breaks for source dependencies - when an external build loaded via ProjectRef(file("ext/lib"), "lib") uses projectMatrix.in(file(".")), the file(".") resolves to the root project's directory instead of ext/lib/.

As a result, the matrix project picks up wrong sources and compilation fails.

**Solution**
Replace base.getAbsoluteFile with IO.resolve((ThisBuild / baseDirectory).value, base). Since ThisBuild / baseDirectory is set per build unit during loading, this correctly resolves against each build's own root directory.

sourceDirectory and unmanagedBase now derive from the resolved projectMatrixBaseDirectory setting.
2026-03-25 22:41:56 -04:00
BrianHotopp b362a0ba91
[2.x] fix: Emit <type> in POM for non-jar explicit artifacts (#8975)
PomGenerator never emitted <type> for dependencies with explicit
artifacts, so a WAR dependency would appear in the POM without
<type>war</type>. Maven then treats it as a JAR dependency, resolving
the wrong artifact.

Uses the primary (non-classifier) artifact to determine the type,
so .withSources()/.withJavadoc() classifier artifacts don't produce
spurious <type>doc</type> or <type>src</type> elements.

Fixes #1979

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 23:51:01 -04:00
Anatolii Kmetiuk 81d379f12d
[2.x] Fix Resolvers test formatting (#8968) 2026-03-23 21:47:42 -04:00
Anatolii Kmetiuk a9347cf220
Merge commit from fork
* Harden Windows VCS URI fragments against command injection

- Use Process(argv) for git/hg/svn without cmd /c on Windows
- Add VcsUriFragment.validate for fragments in clone/checkout/update
- Add tests

* Allowlist-based approach to VCS string sanitization
2026-03-23 20:12:58 -04:00
Dream 8132a392c3
[2.x] feat: Add dependencyMode setting to control classpath transitivity (#8960)
**Problem**
sbt always includes all transitive dependencies on the classpath.
This makes it easy to accidentally depend on transitive dependencies
without declaring them, leading to fragile builds that break when
a library changes its own dependencies.

**Solution**
Add a `dependencyMode` setting with three modes:

- DependencyMode.Transitive (default) — current behavior, all
  transitive dependencies on the classpath
- DependencyMode.Direct — only declared dependencies plus
  scala-library on the classpath
- DependencyMode.PlusOne — declared dependencies plus their
  immediate transitive dependencies plus scala-library

Fixes sbt/sbt#8942
2026-03-23 16:30:16 -04:00
Daniil Sivak 9939666a33
[2.x] fix: server-test and related refactoring (#8904)
- TestServer was replaced with ServerSession class, which is located in protocol module and allows you to interact with JSON-RPC sbt server.
2026-03-21 23:45:37 -04:00
kenji yoshida 6dcb601f73
Add scalafmt newlines.topLevelStatementBlankLines setting (#8949) 2026-03-21 02:58:49 -04:00
xuwei-k 5a74ba3992 Remove return statement in CommandExchange.scala 2026-03-20 15:04:42 +09:00
BitToby be305eb3a5
fix: Use sbt script in BSP config instead of hardcoded Java path (#8920)
**Problem**

sbt bspConfig writes the absolute path of the current Java binary into .bsp/sbt.json. When the user switches Java versions (via sdkman, cs java, etc.) or removes that JDK, the IDE fails to start the sbt BSP server because the hardcoded path is stale or gone.

**Solution**

When an sbt launcher script is available (via `sbt.script` system property or PATH lookup), generate:

"argv": ["/path/to/sbt", "bsp"]
2026-03-19 20:57:53 -04:00
kenji yoshida b8ab0031f1
[2.x] refactor: Remove unnecessary unchecked annotation (#8926) 2026-03-19 20:11:01 -04:00
kenji yoshida 0608a660da
[2.x] refactor: Reduce return statements (#8925) 2026-03-19 20:09:31 -04:00
kenji yoshida 14606c593d
[2.x] ci: Add scalafix DisableSyntax.noReturns (#8922) 2026-03-19 10:48:10 -04:00
BitToby 963acca8ad
[2.x] fix: Preserve user-specified scope axes in command instead of silently discarding them (#8916)
**Problem**
set every silently discards scope axes the user provides. Running:

set every Test / sources := Nil

empties sources in **all** scopes including Compile, not just Test. This happens because rescope in SettingCompletions.setAll strips the scope and forces Global.

**Solution**
Changed rescope to keep the user's config/task/extra axes and only wildcard the project axis. When no scope is given, behavior is unchanged - all axes match everything as before.
2026-03-18 00:53:54 -04:00
Anatolii Kmetiuk e6a2b536bf
Merge pull request #8915 from eed3si9n/wip/virtual-file
[2.x] Add VF keys
2026-03-18 11:37:56 +09:00
Eugene Yokota 5a767e3442 [2.x] Add VF keys
**Problem**
java.io.File cannot participate in cached task.

**Solution**
This adds a few VF-equivalent keys so they can participate
in cached task.
2026-03-17 02:33:13 -04:00
bitloi 7fc522da65 Refactor: extract reportScalaLibEviction for Scala 2.13 and 3 eviction messages 2026-03-16 17:07:31 +01:00
bitloi f4eff2da77 [2.x] fix: Eviction error for downgrade of Scala 3.x (#6694)
**Problem**
When scalaVersion is Scala 3.x and a dependency brings a newer
scala3-library_3, sbt did not report an eviction error or warning.
The compiler could be older than the standard library on the
classpath, breaking compile-time alignment (e.g. scala/scala3#25406).

**Solution**
- In Compiler.scala, add an else if ScalaArtifacts.isScala3(sv) branch
  in scalaInstanceConfigFromUpdate that finds scala3-library_* on the
  Compile report and, if scalaVersion < that revision, fails (or warns
  when allowUnsafeScalaLibUpgrade := true) with the same pattern as
  the existing Scala 2.13 check (PR 7480). Message uses compile-time
  alignment wording and "See evicted to know why ... was upgraded from".
- Set allowUnsafeScalaLibUpgrade := true on b3 in stdlib-unfreeze so
  existing b3/run and b3/checkScala still pass.
- Add scripted tests: stdlib-unfreeze-scala3-eviction (expect compile
  to fail) and stdlib-unfreeze-scala3-warn (expect success with warning).

Closes #6694
2026-03-16 00:15:43 +01:00
bitloi e12b3c9b9a
[2.x] fix: Fixes script mode using Scala 3.x (#8900)
**Problem**
Scripts with scalaVersion 3.x in /*** */ and a shebang fail: -Xscript is
ignored by Scala 3, and the shebang line causes "Expected a toplevel
definition".

**Solution**
- Strip shebang when copying the script so the compiler never sees it.
- For Scala 3 only: do not add -Xscript; generate Main.scala wrapping the
  script body in object Main { def main(...) = { ... } }; use it as the
  single source and set run/mainClass to Main.
- For Scala 2: keep existing behavior (shebang stripped, -Xscript + script
  base name).
- Use Def.uncached and ScalaArtifacts.isScala3(scalaVersion.value) so
  embedded scalaVersion from /*** */ is respected.
2026-03-14 23:28:34 -04:00
seroperson 6dcce4cf2d
[2.x] fix: addressing review comments 2026-03-13 09:34:32 +03:00
seroperson c9fe1635f4
[2.x] feat: updating remote vcs projects
Closes #1284
2026-03-12 13:15:14 +03:00
Dream b3d2733fb1
[2.x] fix: Remove projectDescriptors key that leaks Ivy types (#8894)
**Problem**
The projectDescriptors key in sbt.Keys leaked Ivy classes
(ModuleRevisionId, ModuleDescriptor) through its API surface.
No external plugins use this key.

**Solution**
Remove projectDescriptors entirely. IvyDependencyPlugin now uses
its internal depMap method directly for projectResolverTask and
coursierExtraProjectsTask, eliminating unnecessary Any casts.
The descriptors field is also removed from GlobalPluginData.

Fixes sbt#8865
2026-03-11 14:53:39 -04:00
kenji yoshida d6e6d28f87
Delete checkPluginCross task. Add sourceGenerators for PluginCross (#8897) 2026-03-11 14:40:49 -04:00
kenji yoshida 5fb9f3c5fa
[2.x] refactor: Use InputStream.transferTo (#8896)
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/InputStream.html#transferTo(java.io.OutputStream)
2026-03-11 14:32:40 -04:00
BinaryWorldTl 6821167032
[2.x] fix: Handle scala/toolkit.local when passed as argument to sbt new (#8887)
Running sbt new scala/toolkit.local with the template slug on the command line throws:

The same templates work when chosen from the interactive menu (sbt new with no args). The code path for “arguments provided” only consulted external template resolvers (e.g. Giter8), which do not handle these built-in local templates.
2026-03-10 23:46:51 -04:00
Dream d71fe5b7a3
[2.x] refactor: Extract lm-ivy to separate sbt-ivy plugin module (#8873)
Step 5 of #7640 — removes the compile-time dependency on lm-ivy from main/ by creating a standalone sbt-ivy plugin module.

- Create new sbt-ivy/ subproject with IvyDependencyPlugin AutoPlugin that provides all Ivy-specific functionality (ivySbt, ivyModule, ivyConfiguration, publisher, projectDescriptors, deliver/makeIvyXml)
- Move IvyXml.scala from main/ to sbt-ivy/
2026-03-10 23:30:06 -04:00
kenji yoshida 963e38256c
[2.x] ci: Update java file formatter plugin (#8892) 2026-03-10 11:19:48 -04:00
kenji yoshida 02c403b7cf
Update semanticdbVersion in SemanticdbPlugin.scala (#8885) 2026-03-09 15:39:13 -04:00
kenji yoshida 1926a693da
Update TemplateCommandUtil.scala (#8884) 2026-03-09 14:27:01 -04:00
oolokioo7 e15df63cac
[2.x] fix: sbt-with-loglevel-error (#8883)
**Fix**
Wrap BuiltinCommands.setParser with Act.requireSession(...).
This makes the parser fail gracefully when no session is available, matching the behavior of other session-dependent parsers.
2026-03-08 17:04:37 -04:00
oolokioo7 b3d6c06731
[2.x] dependencyTree: add `--append` for file output in multi-module builds (#8878)
**Summary**
This adds an --append flag to the dependencyTree input task when used with --out. It allows running dependencyTree in multiple subprojects and appending their outputs to the same target file instead of overwriting.

**Solution**
- Add Arg.Append in the CLI parsing
- When --append is set, write using IO.write(..., append = true)
2026-03-06 14:53:18 -05:00
eugene yokota 8a77f7fb03
[2.x] Tweak the prompt (#8876)
**Problem/Solution**
Tweak the shell prompt to differentiate sbt 1.x vs 2.x.
2026-03-05 23:55:04 -05:00
eugene yokota 647dbc47f4
[2.x] Move compiler bridge to Update (#8836)
**Problem**
We want to grab tooling artifacts in update.

**Solution**
This adds binary compiler bridge artifacts into the update graph.
2026-03-04 02:35:38 -05:00
Dream 3579dd0a9f
[2.x] fix: Respect global log level in continuous build watcher (#8864)
**Problem**
Running `sbt -error ~run` still prints [info] messages from the watcher
("Monitoring source files...", "Build triggered by...", etc). The watcher
creates its logger using only the watchLogLevel setting (default Info),
ignoring the global log level set via CLI flags like -error or -warn.

**Solution**
In Continuous.getCallbacks, take the more restrictive of the watchLogLevel
and the global log level from State when configuring the watcher appender.

Fixes #7355
2026-03-04 02:35:18 -05:00
Dream cf9d3d5a7a
[2.x] refactor: Make Ivy keys lazy/optional and flip useIvy default to false (#8866)
- Replace `ivyModule` with Coursier's `dependencyResolution.moduleDescriptor` in the `evicted` task, removing a direct Ivy dependency from the eviction-checking path
- Gate Ivy-specific tasks (`makePom`, `makeMavenPomOfSbtPlugin`, `deliverTask`, `publisher`, `publishOrSkip`, `depMap`, `GlobalPlugin.extract`) behind `useIvy` so they error or return empty when `useIvy = false`
- Fix `.value` hoisting bug in `ivylessPublishTask` where `ivyModule.value` and `publisher.value` inside `match/case` fallback branches were macro-hoisted as task dependencies regardless of runtime path, breaking all ivyless publishes
- Add `ivylessPublishM2Task` so `publishM2` works with `useIvy = false` (publishes to `~/.m2` via `ivylessPublishMavenToFile`)
- Flip `useIvy` default from `true` to `false`
2026-03-03 23:16:28 -05:00
Daniil Sivak 81edea48bc
[2.x] fix: Undefined per-project settings order (#8862)
Closes #7173
2026-03-03 14:09:14 -05:00
Renzo b1db6ba44d
[2.x] feat: support passing JVM arguments via -- delimiter in run commands (#8868)
Summary
- Adds support for passing JVM arguments inline to `run`, `runMain`, `bgRun`, `bgRunMain`, and `fgRun`/`fgRunMain` using `--` as a delimiter
- Syntax: `run <jvmArgs> -- <appArgs>` (e.g., `run -Xmx2G -Dapp.mode=debug -- arg1 arg2`)
- Fully backward compatible — without `--`, all arguments are treated as app args as before
- When `fork` is `false`, a warning is logged that JVM arguments will be ignored
2026-03-02 23:49:10 -05:00