Commit Graph

3827 Commits

Author SHA1 Message Date
bitloi f8b7d61b5a Handle DynamicDepsInitialize in settings evaluation (fix actions/multi-scope MatchError)
- Expose inner Initialize on DynamicDepsInitialize (val inner) in Settings.scala
- Add DynamicDepsInitialize case in INode.scala transform; delegate to inner init
- Include ScopeFilter.scala scalafmt changes
2026-02-09 20:21:20 +01:00
bitloi da3b0deb5f Fix ScopedKey type: use Def.ScopedKey to resolve compiler error 2026-02-09 20:21:20 +01:00
bitloi 258a395fe9 Apply Scala 3 fewer-braces style (contributing-docs/03_coding_style) 2026-02-09 20:21:19 +01:00
bitloi 905862f60c Fix #5647: treat keys consumed via .all(ScopeFilter) as used by lintUnused
- Add Initialize.dynamicDependencies (Seq[Any]) in util-collection to carry
  (AttributeKey, ScopeFilter) from .all() without changing static dependency graph.
- Add DynamicDepsInitialize wrapper and Def.withDynamicDependencies; use them
  in SettingKeyAll.all and TaskKeyAll.all when the init is a KeyedInitialize.
- In LintUnused, collect init.dynamicDependencies from all settings, expand
  via ScopeFilter.expandDynamicDeps (build ScopeFilter.Data from structure,
  apply each filter to get scopes, add ScopedKey(scope, key) to used).
- Add ScopeFilter.dataFromStructure and expandDynamicDeps with try/catch
  so bad filters or structure do not break the lint.
2026-02-09 20:21:19 +01:00
eugene yokota edd7061f15
[2.x] Minimalist console (#8722)
**Problem**
Forked console currently pulls in full Zinc, which includes JLine.

**Solution**
This implements a lighter-weight, full Java ForkConsoleMain,
which no longer depends on JLine.
2026-02-09 10:55:44 -05:00
bitloi f6319f19a3
[2.x] fix: Fixes ThisBuild-scoped keys using root project's aggregates (#8703)
Build-level references (ThisBuild, BuildRef) should not participate
in aggregation. Only project-level references should aggregate.

Previously, when querying `ThisBuild/version`, the aggregation logic
would resolve ThisBuild to a BuildRef, then convert it to the root
project's ProjectRef, causing it to incorrectly use the root project's
aggregate definitions.

The fix uses pattern matching to distinguish BuildReference from other
reference types, returning None (no aggregation) for build-level scopes.

Fixes sbt/sbt#5349
2026-02-07 19:25:55 -05:00
PandaMan 95c6d42f8e
[2.x] fix : BSP compile returns StatusCode.Error on failure (#8104) (#8709)
- BuildServerProtocol: for Result.Inc(cause), return StatusCode.Error for any
  non-InterruptedException (was throwing for non-CompileFailed, causing JSON-RPC
  error instead of BspCompileResult with statusCode Error)
- BuildServerTest: add test 'buildTarget/compile - returns StatusCode.Error
  when compilation fails' (introduce compile error, compile via BSP, assert
  statusCode == Error)
2026-02-07 11:01:49 -05:00
PandaMan f6f00c1931
[2.x] fix: Exclude autoStartServer from lintUnused warnings (#6624) (#8708)
**Problem**
Setting `Global / autoStartServer := false` in global.sbt triggers a
spurious lintUnused warning, even though the setting is correctly used
by sbt's server startup logic.

**Solution**
Add `autoStartServer` to the `excludeLintKeys` set in LintUnused.scala,
similar to other server-related settings like `serverConnectionType` and
`serverIdleTimeout`. This prevents the warning while maintaining the
functionality of the setting.
2026-02-07 10:47:25 -05:00
Eugene Yokota 138621eacb [2.x] client-side console and fixes
**Problem**
1. forked console is missing user code from the classpath.
2. forked console still blocks the server.

**Solution**
1. This includes proper products and classpaths to the console.
2. This also implements client-side run for console.
2026-02-07 00:42:54 -05:00
Eugene Yokota f6799830c7 Move consoleTask 2026-02-06 23:56:30 -05:00
calm 772f616a29
[2.x] fix: Restore Scala 2 artifact version unification (#8689) (#8700)
Commit 92b0564dc (fix for #8632) changed `csrSameVersions` so that Scala 2.13+ only aligned `scala-library` and `scala3-library`. This removed `scala-compiler` and `scala-reflect` from version
unification, so transitive dependencies pulling in an older `scala-compiler` (e.g. 2.13.15 via `refined_2.13`) were no longer evicted to match `scalaVersion` (e.g. 2.13.18).
2026-02-06 19:55:41 -05:00
bitloi 4e0180d759
[2.x] fix: Use correct configuration identifier for display (#8698)
**Problem**
The configuration name translation in logging was incorrect. When a
configuration like MultiJvm (id="MultiJvm", name="multi-jvm") was
displayed, it showed "Multi-jvm" instead of "MultiJvm" because the
display logic was guessing the identifier by capitalizing the ivy
config name.

**Solution**
This fix:
- Adds configNameToIdent reverse mapping in ConfigIndex to look up
  the correct Configuration.id from the ivy config name
- Adds toConfigIdent method in KeyIndex trait for display lookup
- Updates Scope.display to accept a config name lookup function
- Updates showLoadingKey and showContextKey to use the index lookup

Fixes #5211

Generated-by: Claude
2026-02-06 12:54:58 -05:00
calm 47e7133260
[2.x] feat: drop other idle servers on client exit (#8610) (#8701)
Implements cooperative idle server cleanup for `sbtn` (issue #8610). When a client disconnects from an sbt server, that server notifies all
other registered servers to shut down if they've been idle long enough and have no connected clients. This prevents accumulation of idle
background JVMs across projects.

fixes #8610
2026-02-06 12:52:36 -05:00
bitloi 52bc35e3a9
[2.x] fix: allow defining root project with extraProjects (#4976) (#8694)
When an AutoPlugin adds a project at the build root via extraProjects,
avoid creating a second root from the build definition so both do not
share the same target directory. Treat extraProjects root as 'root
already defined' and exclude the build-defined root from initialProjects
when both would be at the same base.
2026-02-05 19:07:30 -05:00
bitloi 54548041cf
[2.x] feat: Ivyless Maven repo publish (#8692)
- Add ivylessPublishMavenToFile and ivylessPublishMavenToUrl for Maven layout
- Handle MavenCache and MavenRepo in ivylessPublishTask (file + HTTP)
- Add credentialFor for realm+host credential matching per Publishing docs
- Consume HTTP response body on success to avoid connection leak
- Add scripted tests: ivyless-publish-maven, ivyless-publish-maven-http
2026-02-05 11:21:31 -05:00
bitloi 2f27b5cecd
[2.x] fix: extraProjects with auto-root aggregate breaks key aggregation (#8690)
When using the aggregated key parser, a key is now valid if it exists in `data` for that scope **or** it's an aggregate key and every key it aggregates to exists in `data`. So `(root, scripted)` is accepted when the root aggregates a project that defines `scripted`, and running `scripted` at root runs it on that project as before.
2026-02-04 23:25:47 -05:00
bitloi b460bb871e
[2.x] feat: Ivyless publish to Ivy repo (#8686)
Implements ivyless publish task as part of #7639 (drop Ivy dependency).
Fixes #8639.

- Add ivylessPublish for URLRepository: HTTP PUT with optional Basic auth,
  same layout as ivyless publishLocal (artifacts + ivy.xml + checksums).
- Add ivylessPublishToFile for FileRepository: write to local path for
  testing without HTTP server.
- Add ivylessPublishTask: when useIvy is false, use ivyless path for
  URLRepository or FileRepository; otherwise use Ivy.
- Wire publish in Defaults to LibraryManagement.ivylessPublishTask
  (tagged Publish, Network).
- Add scripted test dependency-management/ivyless-publish using
  Resolver.file to verify ivyless publish produces identical layout.

Credentials supported via allCredentials (Basic auth for PUT).
2026-02-04 14:20:38 -05:00
bitloi b0601b4c6c
[2.x] fix: Fixes subproject deps with different Scala versions (#8681)
When a project depended on another project that was built with a different Scala binary version (e.g. 2.12 vs 2.13), compilation could fail with "not found: value X" because resolution was asking for the wrong artifact.

This change updates how we build the `ModuleID` for inter-project dependencies in `projectDependenciesTask`: we now request the dependency’s Scala binary version (e.g. `bar_2.12`) instead of the current project’s, so the resolver can find the right artifact. We keep existing behavior for `Disabled` and `Constant` cross-version, and add a small safeguard in the default case when the dependency’s Scala version differs from the current project’s.
2026-02-03 13:40:00 -05:00
bitloi 4c16466672
[2.x] feat: Support Maven BOM (Bill of Materials) (#8675)
**Consuming BOMs**

- You can declare a BOM with `.pomOnly()` and versionless deps with `"*"`:
  - `libraryDependencies += ("com.fasterxml.jackson" % "jackson-bom" % "2.21.0").pomOnly()`
  - `libraryDependencies += "com.fasterxml.jackson.core" % "jackson-core" % "*"`
- BOMs are passed to Coursier via `Resolve.addBom()`; version `"*"` is resolved from the BOM.

**makePom**

- POM-only dependencies are emitted under `<dependencyManagement><dependencies>...</dependencies></dependencyManagement>` with `<type>pom</type>` and `<scope>import</scope>`.
- Dependencies with version `"*"` are emitted without a `<version>` element so Maven uses the BOM-managed version.

**Ivy / publishLocal emulation**

- When publishing to Ivy (e.g. `publishLocal`), BOM-resolved versions (deps that had `"*"`) are written into the published `ivy.xml` as forced dependencies (`force="true"`), so consumers that depend on this module get those versions.
2026-02-02 10:54:43 -05:00
bitloi a76074a602
[2.x] fix: skip writing sbt.version in scripted test directories (#8673)
**Problem**

1. Write a scripted test that runs sbt in that test.
2. sbt writes `sbt.version` under `project/build.properties`, which acts as a test filter.
3. The test setup is implicitly altered.

**Solution**

Before writing `build.properties`, sbt checks whether the base directory is inside a scripted test directory (path contains `sbt-test`). If so, it skips writing so the test setup is not altered.
2026-02-01 18:02:17 -05:00
bitloi 4430d4c553
[2.x] feat: add rootProject macro (#8671)
Add a rootProject convenience macro that expands to a Project with base "."
and the enclosing val name as id. Allows writing `val root = rootProject`
instead of `val root = (project in file("."))` for a stable root project id.
2026-02-01 01:07:10 -05:00
bitloi 4dfe68a681 fix: Resolve ThisProject to empty to avoid cycle in aggregate/deps DAG
Resolving ThisProject to ProjectRef(uri, p.id) created a self-reference
in the aggregate (and dependency) list. BuildUtil.checkCycles runs
topological sort on this relation and throws Cyclic when it sees the
self-loop.

Treat ThisProject as no-op: resolve to Vector.empty so the build loads
without error. aggregate(ThisProject) / dependsOn(ThisProject) is
effectively a no-op (self is already included).
2026-02-01 01:59:46 +01:00
bitloi 1a6039c17a Handle ThisProject in aggregate and dependencies
Fixes #3616 - Scope's resolveProjectBuild and resolveProjectRef
mishandle ThisProject.

Previously, using ThisProject in aggregate() or dependsOn() would
cause a runtime error: 'Cannot resolve ThisProject w/o the current
project'.

This change adds proper handling for ThisProject in Load.scala:
- In checkAll: Skip validation for ThisProject (refers to self)
- In resolveProjects: Resolve ThisProject to ProjectRef(uri, p.id)
2026-02-01 01:06:07 +01:00
bitloi d633de5c3f
[2.x] fix: Detect alias/task key name conflicts (#8659)
Problem
When a user defines an alias with a name that matches an existing task or setting key (e.g., `alias c = compile` when a custom task `c` exists), the alias silently wins and shadows the task.

Solution
Detect conflicts at alias creation time and fail with an error message:
```
Alias 'c' conflicts with a task or setting key of the same name. Use a different alias name to avoid ambiguity.
```
2026-01-31 17:56:42 -05:00
bitloi 1ad6b88742
[2.x] feat: Per-channel project cursor for multi-client server mode (#8649)
**Problem**
When multiple clients connect to the same sbt server, they all share the same "current project" state. When one client switches projects with `project X`, all other clients see that change.

**Solution**
Store per-channel project cursors in State attributes. Each client maintains its own cursor that tracks which project it has selected.
2026-01-29 23:15:39 -05:00
bitloi 627c484cd8
[2.x] fix: Restore bincompat for ScriptedRun methods (#8654)
In PR #8621, I added a new `keepTempDirectory` parameter to `ScriptedRun.run()` and `invoke()` methods. To suppress MiMa warnings, I added `mimaBinaryIssueFilters` for:
- `DirectMissingMethodProblem("sbt.ScriptedRun.run")`
- `DirectMissingMethodProblem("sbt.ScriptedRun.invoke")`
- `DirectMissingMethodProblem` for various internal `RunV1`, `RunV2`, `RunInParallelV1`, `RunInParallelV2` classes

However, this broke binary compatibility, which prevents sbt 1.x from calling sbt 2.x for cross-building (building sbt 2.x plugins using sbt 1.x).
2026-01-29 11:07:44 -05:00
eugene yokota cc0915fed9
[2.x] refactor: Scala Instance (#8648)
**Problem**
Strings are used to pass paths around.

**Solution**
This cleans up the Scala instance construction code.
2026-01-28 02:27:57 -05:00
calm 5789a7ef77
[2.x] feat: Implement ivyless publishLocal (#8634)
Fixes #8631

**Changes:**
- Add `useIvy` setting key (defaults to `true`)
- Add `ivylessPublishLocalImpl` helper that publishes without Ivy
- Modify `publishLocal` to use ivyless publisher when `useIvy := false`
- Generate ivy.xml via `lmcoursier.IvyXml`
- Generate MD5/SHA-1 checksums for all files
- Add scripted test `dependency-management/ivyless-publish-local`
2026-01-27 00:05:43 -05:00
eugene yokota 92b0564dc6
[2.x] fix: Fix scala-reflect not found problem (#8632)
## Problem
We enforce same-version policy for scala-reflect in Scala 2.13.
However due to sandwich dependency, the graph can bump
scala-library to 3.8.1, which is missing scala-reflect counterpart.

## Solution
Drop the same-version policy.
2026-01-26 04:55:07 -05:00
calm 9951a302c9
[2.x] feat: Support fork in console task (#8604)
When enabled, the Scala REPL runs in a separate JVM.
2026-01-25 02:16:49 -05:00
Eugene Yokota eaada0494d Fix common settings loading 2026-01-25 01:29:09 -05:00
Eugene Yokota 19ca2911d2 Scala 3.8.1 2026-01-24 04:52:28 -05:00
Eugene Yokota 9813e60fe3 refactor: Clean up infix etc 2026-01-24 04:52:28 -05:00
bitloi f8704752e0
[2.x] feat: Add scriptedKeepTempDirectory setting (#8621)
**Problem**

When running scripted tests to debug sbt plugins, the temporary directories (`/private/var/folder/...`) are automatically deleted after tests complete. This makes it difficult to inspect the test state for debugging purposes, requiring workarounds like adding `$ pause` commands and manually copying directories.

**Solution**

Added a new `scriptedKeepTempDirectory` setting that allows users to preserve temporary directories after scripted tests complete. When enabled, the temporary directory path is logged so users can inspect it.

Usage:
```scala
scriptedKeepTempDirectory := true
```
2026-01-23 21:22:50 -05:00
bitloi 64dadd6459
[2.x] fix: Throw on addCompilerPlugin(foo % Test) (#8622)
Problem

When using `addCompilerPlugin((dependency) % Test)`, the compiler plugin was incorrectly added to BOTH `test:scalacOptions` AND `compile:scalacOptions`, instead of only `test:scalacOptions`.

Solution

Throw when the dependency is scoped, since we do not support this use case.
2026-01-23 11:41:16 -05:00
calm 398af2eaaa
[2.x] fix: Suppress "Multiple main classes" warning for runMain commands (#8613)
Changed the scope separator parsing from `/` only to `[/:]` to handle both new slash syntax (`Test/runMain`) and old colon syntax (`test:runMain`).
2026-01-22 12:58:53 -05:00
calm 2380ab84b6
[2.x] feat: testOnly as a command (#8607)
Adds `testOnly` command that fails when no tests match the specified patterns across all aggregated subprojects.
2026-01-22 04:53:54 -05:00
calm f4ab500d19
[2.x] fix: Use -external-mappings for Scala 3 doc task #6652 (#8602)
**Problem**

When `autoAPIMappings := true` is set on a Scala 3 project, running `sbt doc` emits warnings:

```
[warn] bad option '-doc-external-doc:/modules/java.base#https://docs.oracle.com/...
```

This happens because Scala 3's scaladoc doesn't recognize Scala 2's `-doc-external-doc` option.

Fixes #6652

**Solution**

- Added `Opts.doc.externalAPIScala3` that generates the Scala 3 format: `-external-mappings:regex::[scaladoc3|javadoc]::url`
- Modified `Defaults.scala` to use the appropriate method based on Scala version
- Added heuristics to detect javadoc vs scaladoc based on file/URL patterns
2026-01-22 02:13:10 -05:00
MkDev11 2a5746cf6c
[2.x] feat: Add dependency lock file support (#2989) (#8581)
**What it does**

When you run `dependencyLock`, sbt generates a `deps.lock` file that captures your resolved dependencies. This file can be checked into version control to ensure reproducible builds across different machines and CI environments.

**New tasks**

- **`dependencyLock`** - Generates the lock file from the current resolution
- **`dependencyLockCheck`** - Validates the lock file is up-to-date (fails build if stale)

**How it works**

The lock file stores a hash of your declared dependencies and resolvers. When dependencies change, the hash changes, and `dependencyLockCheck` will fail until you regenerate the lock file.

If no lock file exists, `dependencyLockCheck` passes silently - this allows gradual adoption.
2026-01-21 19:08:59 -05:00
calm 1b8e3317f9
[2.x] feat: Add "3-latest.candidate" support for Scala 3 release candidates (#8596)
Add support for `"3-latest.candidate"` to automatically resolve to the latest Scala 3 RC from Maven Central.

```scala
scalaVersion := "3-latest.candidate"
```

Ref https://github.com/sbt/sbt/discussions/8590
2026-01-21 03:42:50 -05:00
azdrojowa123 6493707d2f
[2.x] fix: Create `project` directory if extra sbt files are added to the meta-build #8570 (#8586) 2026-01-20 10:02:58 -05:00
MkDev11 6f14de514b
[2.x] feat: Add setup-java action support in CrossJava (#8574)
Add SetupJavaDiscoverConfig to detect JDKs installed by GitHub's
setup-java action at paths like:
- /opt/hostedtoolcache/Java_Zulu_jdk/25.0.1-8/x64 (Linux)
- C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\11.0.29-7\x64 (Windows)

These JDKs are now available in fullJavaHomes as zulu@25.0.1,
temurin@11.0.29, etc.

Supported vendors: Zulu, Temurin, Adopt, Corretto, Liberica,
Microsoft, Semeru. Temurin-Hotspot and Adopt are normalized to
temurin.

Fixes #8582

* test: Refactor setup-java tests to use real directory structure

---------

Co-authored-by: mkdev11 <noreply@users.noreply.github.com>
2026-01-20 09:35:43 -05:00
byteforge c5af677632
[2.x] feat: Support ... as testOnly pattern (#8577) 2026-01-19 18:45:29 -05:00
E.G 402619fc45
[2.x] fix: Format Seq values consistently in multi-project builds (fixes #7339) (#8567)
When running commands like 'Test/definedTests' on multi-project builds,
the output was showing raw Vector(...) format instead of nicely formatted
per-item output.

Before:
  [info] svc / Test / definedTests
  [info]   Vector(Test FooSpec : ..., Test BarSpec : ..., ...)

After:
  [info] svc / Test / definedTests
  [info]   * Test FooSpec : ...
  [info]   * Test BarSpec : ...

The fix extends printSettings to check if values are Seq types in
the multi-project case and format each item on its own line with
a '* ' prefix, matching the single-project behavior.
2026-01-17 14:37:42 -05:00
eugene yokota 8b4b89c395
[2.x] Disable delegation on shell (#8539)
**Problem**
Currently the shell delegates request tasks even when a non-existent
task like Compile / update is requested.

**Solution**
This removes the delegation, if the input key is scoped, so it will fail.
We will, however, continue to delegate on the subproject axis,
since it's useful to use Global or ThisBuild scoping.
2026-01-17 00:05:21 -05:00
bitloi c832fad7b5
[2.x] feat: Notify sbtn client when command is queued (#8568)
Fixes #8356

**Problem**

When `sbtn` sends a command while another long-running task (like `console`) is already executing, the client silently blocks with no indication that the command is waiting in a queue.

**Solution**

When a new command arrives via the network channel and another command is currently running, the server now sends an `ExecStatusEvent` notification with status `"Queued"` to the client. The client displays a message like:

```
[info] waiting for: console
```
2026-01-16 16:17:00 -05:00
Pegasus 79c60ca4c1
[2.x] fix: Allow dependencyTree to run despite eviction errors (#8554)
**Problem**
When binary compatibility eviction errors occur, users cannot run
`dependencyTree` to debug the dependency conflict because it fails
with the same eviction error.

**Solution**
Set `evictionErrorLevel` and `assumedEvictionErrorLevel` to `Level.Warn`
for the `dependencyTreeIgnoreMissingUpdate` task, allowing the dependency
tree to be displayed even when eviction errors are present.

Fixes #7255
2026-01-15 22:52:38 -05:00
E.G 009b0e1276
[2.x] test: Migrate FileStampJsonSpec.scala to verify.BasicTestSuite (#8552)
Co-authored-by: GlobalStar117 <GlobalStar117@users.noreply.github.com>
2026-01-15 15:01:57 -05:00
MkDev11 b58c0fb37f
[2.x] fix: Cleanup child processes on sbt exit (#8532)
When using fork := true, sbt spawns child processes that may become
stale if cancelled. Previously, these processes were not cleaned up
when running the exit command.

This fix adds RunningProcesses.killAll() to the shutdown hook so that
all tracked forked processes are terminated when sbt exits.

Fixes #7468
2026-01-14 15:57:50 -05:00
MkDev11 f85ced45f2
[2.x] fix: Start server when explicitly requested via BSP/thin client (#8529)
Fixes #7481

When sbt is started by a remote client (BSP or thin client via --server flag),
always start the server regardless of autoStartServer setting. The autoStartServer
setting is meant for automatic server startup, not for blocking explicit server
start requests.
2026-01-14 04:57:05 -05:00