Commit Graph

17653 Commits

Author SHA1 Message Date
aka James4u dce915e794
[2.x] fix: Error "Exception in thread "sbt-socket-server" java.lang.NullPointerException" on exit (#8448)
Fixes #8538

The code was calling e.getMessage.contains() without checking if getMessage()
returns null. Changed to use Option(e.getMessage).exists() to safely handle
null values.
2026-01-15 11:06:51 -05:00
Dairus 7368252678
[2.x] fix: Skip checksums for PGP signature files (.asc) (#8535)
## Problem
When using `publishSigned` (via sbt-pgp), sbt creates checksum files (e.g., `.pom.asc.sha1`) for PGP signature files (`.asc`). This violates Maven norms, where checksums should only be generated for raw artifacts like JARs and POMs, not for signatures.

## Solution
Modified the checksum generation logic in `ChecksumFriendlyURLResolver.put` (in `lm-ivy/src/main/scala/sbt/internal/librarymanagement/ConvertResolver.scala`) to skip generating checksums for artifacts whose names end with `.asc`.
2026-01-15 01:04:33 -05:00
MkDev11 b2db55768c
[2.x] fix: Log server response body on publish failure (#8537)
When publishing to a repository fails with an HTTP error (e.g., 403, 409), the server often includes helpful error details in the response body. Previously, sbt only showed the HTTP status code without the response body.

This reimplements the upload method.

Fixes #7423
2026-01-15 00:23:31 -05:00
MkDev11 fb53925fb6
[2.x] fix: Prevent sbt test from hanging when forked process crashes (#8536)
When a forked test process crashes (e.g., due to UnsupportedClassVersionError),
sbt would hang forever waiting for test results. This happened because
notifyExit only completed the promise with success, regardless of the
exit code.

This fix checks the exit code and fails the promise if the process
exited with a non-zero code, allowing sbt to properly report the failure
and exit.

Fixes #7429
2026-01-14 21:54:17 -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 1ed08f0034
[2.x] fix: Propagate SBT_OPTS to BSP config (#8531)
Fixes #7469

When running 'sbt bspConfig', the generated .bsp/sbt.json now includes
JVM options from the SBT_OPTS environment variable. This ensures that
options like -Dsbt.boot.directory are propagated to the BSP server.

The parseSbtOpts method extracts -D, -X, and -J prefixed options from
SBT_OPTS and includes them in the BSP connection argv.
2026-01-14 14:20:30 -05:00
Dairus 8433dd8db6
[2.x] test: Migrate CleanStringSpec to verify.BasicTestSuite (#8526) 2026-01-14 11:10:40 -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
MkDev11 7b33362245
[2.x] fix: Preserve user-defined scalacOptions in doc task scope (#8528)
Fixes #7482
2026-01-14 00:57:42 -05:00
MkDev11 82e370b4cb
[2.x] fix: inputFileChanges with nested task scopes (#8516)
Fixes #7489

When using nested task scopes like otherTask / testTask, the
inputFileChanges macro was returning the wrong scope. It checked
if the scope already had a task axis and returned it as-is, but
this meant it would use otherTask's scope instead of testTask's.

The fix always sets the task axis to the key being queried,
ensuring fileInputs settings are found at the correct scope.
2026-01-14 00:10:23 -05:00
MkDev11 e16298521b
[2.x] feat: Enable musl static linking for sbtn on JDK 17+ (#8464)
** Problem **

The sbtn (sbt thin client) native image on Linux currently depends on glibc because ipcsocket uses JNI for Unix domain sockets. When building with musl for static linking, the JNI library fails to load since musl doesn't support `dlopen`.

** Solution **

Instead of upgrading to ipcsocket 2.x (which isn't ready for production), I created a `UnixDomainSocketFactory` that detects JDK 17+ at runtime and uses the native `java.net.UnixDomainSocketAddress` API directly via reflection. This completely bypasses JNI on modern JDKs.

For older JDKs (8 and 11), the factory falls back to ipcsocket 1.6.3, which is stable and well-tested.

** How It Works **

The factory checks at startup whether `java.net.UnixDomainSocketAddress` is available:

- **JDK 17+**: Uses native NIO Unix domain sockets (no JNI, no native libraries)
- **JDK 8/11**: Falls back to ipcsocket's JNI-based implementation

This approach:
- Enables musl static linking on JDK 17+ without any native dependencies
- Maintains full backward compatibility with older JDKs
- Keeps the stable ipcsocket 1.6.3 instead of the unstable 2.x
2026-01-13 23:14:45 -05:00
SID 0c6b4c9741
[2.x] Fix watchTriggers to control what triggers instead of adding to fileInputs (#8525)
When watchTriggers is explicitly set (non-empty), use only watchTriggers
instead of combining them with fileInputs. This allows users to control
what triggers the watch by setting watchTriggers.

Fixes #7130
2026-01-13 21:14:10 -05:00
Satoshi Dev 43e0428bed
[2.x] fix: trim whitespace from sbt.version in build.properties (#8524)
When sbt.version in build.properties has trailing whitespace,
sbt incorrectly reports a version mismatch even after reboot.

This fix trims the property value in all places where sbt.version
is read from build.properties:
- Main.scala (version mismatch warning)
- MainLoop.scala (clean command version detection)
- ScriptedTests.scala (test compatibility check)

Fixes #8103
2026-01-13 21:13:47 -05:00
kenji yoshida eb81ff9000
[2.x] deprecate useLog4J SettingKey (#8523) 2026-01-13 18:46:41 -05:00
Match 727f4b05c6
fix: Fix NoClassDefFoundError after changing val in build.sbt (#8521)
**Problem**

When a val definition in build.sbt changes and the user runs `reload`, sbt crashes with `NoClassDefFoundError: $Wrap<hash>$`.

```
java.lang.NoClassDefFoundError: $Wrape8743d4f36$
  at $Wrap0b8ea34d40$.$anonfun$1(build.sbt:1)
```

The workaround was to delete `project/target` directory.

**Solution**

The root cause was that imports were not included in the hash calculation when evaluating build.sbt expressions. When a val definition changes:
1. Its `$Wrap` module gets a new hash
2. Settings that reference the val get new imports pointing to the new module
3. But if the setting expression didn't change, its hash was the same
4. The old cached class was loaded with bytecode referencing the old module

Fix: Include imports in the hash calculation in `Eval.evalCommon`. Also re-enable `cleanEvalClasses` in `Load.scala` which was disabled pending this fix.
2026-01-13 18:45:16 -05:00
kenji yoshida dc0d055069
[2.x] Remove unused code in project/Dependencies.scala (#8522) 2026-01-13 18:43:08 -05:00
Dairus 4a36171138
[2.x] fix: Fix whatDependsOn RuntimeException (#8462)
Filters out empty versions during parser construction to prevent RuntimeException when creating token parsers.  Includes comprehensive test coverage for edge cases.

DependencyTreePlugin is an AutoPlugin with trigger = AllRequirements,
so it loads automatically in scripted tests without requiring explicit
plugin configuration.
2026-01-13 17:12:57 -05:00
SalesforcePeak 1ef5823a49
[2.x] fix: Log created in Commands not whowing up in WARN or ERROR Log Levels (#8515) 2026-01-13 14:45:15 -05:00
Match 88e2f2704f
[2.x] fix: Fixes --no-colors setting for sbtn (#8517) 2026-01-13 14:44:09 -05:00
SID bb02c3331c
[2.x] fix: Fix sbtopts files priority in sbt launch script (#8514)
* Fix sbtopts files priority in sbt launch script (fixes #7179)

- Change project .sbtopts from prepend to append so it appears last
2026-01-13 13:30:13 -05:00
MkDev11 4ed22747dc
[2.x] fix: Check cache file exists before reading in Eval (#8513)
Fixes #8511

When loading a cached build definition, the code checked if the .class
file exists but not the .cache file. If the .cache file was missing
(deleted, corrupted, or from a partial compilation), it threw
NoSuchFileException.

Now both files are checked before using the cache. If either is missing,
the build definition is recompiled.
2026-01-13 11:31:43 -05:00
MkDev11 28f7957307
[2.x] fix: Fix sbt new argument parsing on Windows (#8509)
Only recombine split -- arguments after new/init command.

Fixes #7507
2026-01-13 05:19:19 -05:00
MkDev11 d4570e3359
[2.x] fix: Skip native client for sbt new/init commands (#8512)
Fixes #7497
2026-01-13 05:18:05 -05:00
eugene yokota 570ca30f69
[2.x] test: Test -Werror in metabuild (#8510)
**Problem**
-Werror in the metabuild didn't work on sbt 1.x.

**Solution**
This adds test for it on sbt 2.x.
2026-01-13 04:28:27 -05:00
MkDev11 02dcab80b9
Fix StackOverflowError when reporting self-referencing exceptions (#8508)
Add circular reference detection to StackTrace.trimmedLines using an
IdentityHashMap-backed Set, similar to how the JDK handles this in
Throwable.printStackTrace().

When a circular reference is detected, the method now appends a
[CIRCULAR REFERENCE: ...] message instead of recursing infinitely.

Fixes #7509
2026-01-12 23:53:44 -05:00
MkDev11 f2a5ae7219
[2.x] fix: Use strict matching for scala-library jar detection (#8507)
Fixes #7511

The previous check used contains("scala-library") which incorrectly
matched any jar with that substring anywhere in the filename, causing
user libraries named like "my-scala-library-foo" to be misclassified
as the Scala standard library and filtered from the classpath.

Changed to use exact match (scala-library.jar) or prefix match
(scala-library-*) to only match the actual Scala library jars,
consistent with how scala-reflect is detected on line 199.
2026-01-12 23:50:01 -05:00
Satoshi Dev 3a9e1ec725
[2.x] fix: Fix pipelining flags applied to unsupported Scala versions (#8499)
Scala 2.x has supported pipelining since 2020. The fix now allows:
- All Scala 2.x versions (pipelining supported)
- Scala 3.5.0+ (pipelining added in 3.5)

Generated-by: AI-assisted
2026-01-12 22:44:49 -05:00
Saber aeabb90d2d
[2.x] feat: dependencyLicenseInfo (#8506)
* Add JSON output support to dependencyLicenseInfo

- Add LicenseInfo rendering object with text and JSON output
- Add dependencyLicenseInfo input task key
- Implement dependencyLicenseInfo task with JSON format support
- Supports --out option for file output
- Auto-detects JSON format from .json file extension
- Follows same pattern as dependencyTree task

Resolves #7771
2026-01-12 22:16:40 -05:00
MkDev11 847703cd5e
[2.x] fix: Allow ++ command to accept project/command patterns not in current state (#8505)
When using '++version project/task', the parser now accepts project/command
patterns (e.g., 'docs/docusaurusPublishGhpages') even if the project doesn't
exist in the current state. This is achieved by adding a fallback parser
that accepts any 'project/command' pattern alongside the combinedParser.

Previously, '++2.12.19 docs/task' would fail with 'Project not found' if
'docs' project wasn't available in the current Scala version, but
'++2.12.19; docs/task' worked. Now both syntaxes work correctly.

The fix is targeted to only accept slash-delimited patterns, avoiding
interference with other parser components like the -v verbose flag.

Fixes #7574
2026-01-12 22:14:01 -05:00
azdrojowa123 106b8b9978
[2.x] Always create symlinks to the cache in the target locations #8445 (#8461)
* always create symlinks to the cache in the target locations, even if the digest matches #8445
* create a test (currently failing even on #develop) that fails because if `zipPath` in `sbt.util.ActionCache.packageDirectory` is a symlink to the CAS, in later calls, this path in the CAS gets overridden by the new sources.

- in this test, after "run 1" in line 15, the produced file "target/out/jvm/scala-3.7.4/a/classes.sbtdir.zip" is a symlink to the CAS, let's call it SH1.
- when "run 3" is executed, `IO.zip` saves the new value to `zipPath`, which is "target/out/jvm/scala-3.7.4/a/classes.sbtdir.zip -> SH1", so SH1 gets overridden.
- when the last "run 1" is executed, the cache retrieves SH1, but it contains the data from "run 3" (the test fails with "actual A.x is 3").

* when packaging a directory into a zip, use a temp directory to avoid overwriting the cache #8461
2026-01-12 19:38:59 -05:00
MkDev11 81b6408f49
[2.x] feat: Add csrLocalArtifactsShouldBeCached setting for caching local artifacts (#8504)
This adds a new setting  that allows users to
configure Coursier's FileCache to cache local file:// artifacts. When enabled,
artifacts from local repositories are copied to the cache directory, which is
useful for scenarios like bundling compiler artifacts in a local repo for
offline use.

Fixes #7547
2026-01-12 19:17:55 -05:00
kenji yoshida 56c86a1684
[2.x] Delete TrapExitSecurityException (#8503) 2026-01-12 19:11:35 -05:00
kenji yoshida f31290b809
[2.x] Update project/PublishBinPlugin.scala (#8498)
avoid useCoursier. prepare sbt 2
2026-01-12 16:20:23 -05:00
calm ebc11f04a7
[2.x] fix: Fix updateSbtClassifiers using wrong Scala version for cross-built plugins (#8495)
**Problem**

When cross-building sbt plugins with explicit `scalaVersion` set in `build.sbt`, the `updateSbtClassifiers` task fails because it uses the launcher's Scala version instead of the appropriate Scala version for the target sbt version.

For example, with this configuration:
```scala
lazy val root = (project in file("."))
  .enablePlugins(SbtPlugin)
  .settings(
    scalaVersion := "2.10.7",  // Explicit for IDE support
    crossSbtVersions := Seq("0.13.17", "1.0.0"),
  )
```

Running sbt "show updateSbtClassifiers" would fail with:
Error downloading org.scala-sbt:scripted-plugin_2.12:0.13.17

It should look for scripted-plugin_2.10:0.13.17 since sbt 0.13.x uses Scala 2.10.

**Solution**

Modified sbtClassifiersTasks in Defaults.scala to:
1. Check if the project is an sbt plugin (sbtPlugin.value)
2. For plugins, derive the Scala version from pluginCrossBuild / sbtBinaryVersion using PluginCross.scalaVersionFromSbtBinaryVersion
3. For non-plugins, continue using the launcher's Scala version (original behavior)
2026-01-12 16:19:24 -05:00
calm b4f73c9a7b
[2.x] fix: Invalidate update cache across commands when dependencies change (#8501)
**Problem**
When project A's dependencies changed and A was compiled in one command, project B (depending on A) would not invalidate its update cache in a subsequent command. This caused stale classpaths.

The root cause was that `depsUpdated` only checked `!stats.cached`, which only detected fresh resolves within the same command. When a dependency was served from cache (even if resolved fresh in a previous command), `cached` was marked `true`, causing incorrect cache reuse.

Debug scenario from issue:
sbt:aaa> clean
sbt:aaa> a/compile
sbt:aaa> show itTests/depsUpdated
[info] * false   <-- BUG: should be true

**Solution**
Added `stamp: String` field to `UpdateStats` that records when the update was resolved. This stamp persists across commands and enables accurate cross-command comparison:

- If any dependency's stamp > our cached stamp, we re-resolve
- Falls back to `!cached` check for backwards compatibility with old caches
- Using `String` type allows future transition from timestamps to content hashes
2026-01-12 16:17:51 -05:00
MkDev11 fe6125d8d1
[2.x] feat: Cache failed compilation to avoid repeated failures (#8490)
When a compilation fails with CompileFailed, the failure is now cached
so that subsequent builds with the same inputs don't re-run the failed
compilation. This significantly improves the experience when using BSP
clients like Metals that may trigger many compilations in a row.

The implementation:
- Adds CachedCompileFailure, CachedProblem, and CachedPosition types
  to serialize compilation failures
- Modifies ActionCache.cache to catch CompileFailed exceptions and
  store them in the cache with exitCode=1
- On cache lookup, checks for cached failures first and re-throws
  the cached exception if found
- Fixes DiskActionCacheStore.put to preserve exitCode from request
- Adds unit test to verify cached failure behavior

Fixes #7662
2026-01-12 16:03:05 -05:00
kenji yoshida bc32efbea6
refactor: Add parentheses to PathFinder.get (#8497) 2026-01-12 15:19:40 -05:00
kenji yoshida 0fa17f7705
Update sbt plugins (#8496) 2026-01-12 15:19:07 -05:00
MkDev11 add43bd230
feat: Set terminal window title when running applications (#8492)
Set window title to 'sbt <command>: <org> % <name> % <version>' when
running sbt run, runMain, bgRun, or bgRunMain.

For server-side runs, window title is set directly. For client-side runs (sbtn), window title is passed via RunInfo protocol
and set by NetworkClient.

Fixes #7586
2026-01-12 02:32:52 -05:00
MkDev11 0ec500392f
[2.x] ci: Handle undefined crossScalaVersions in publishLocalAllModule (#8491)
The publishLocalAllModule command fails with 'crossScalaVersions is
undefined' when the zinc submodule's compilerBridge project doesn't
have crossScalaVersions defined.

This is a long-standing issue that was reported in #4387 (2018) and
'magically resolved' when zinc happened to define the setting, then
resurfaced in #7607 (2024) when zinc changed.

The fix uses getOpt().getOrElse(Nil).toList instead of get().toList
to handle the case where crossScalaVersions is not defined, allowing
the command to proceed gracefully.

Fixes #7607
2026-01-12 01:42:39 -05:00
eugene yokota 88812f27a3
Merge pull request #8494 from calm329/fix/8442-server-subprocess-hang-linux
[2.x] fix: Prevent server subprocess hang on Linux (#8442)
2026-01-12 00:50:42 -05:00
calm329 476730aba2 fix: Prevent server subprocess hang on Linux (#8442) 2026-01-11 21:00:57 -08:00
calm e7323171a2
fix: Handle relocated dependencies in dependencyTree (#8400) (#8489) 2026-01-11 21:27:11 -05:00
MkDev11 21b5c3b8df
[2.x] fix: Fix snapshot sbt version invalidation 7713 (#8486)
When using a SNAPSHOT version of sbt, if the sbt jars are republished
with breaking binary changes, the build definition should be recompiled.
Previously, the cache key only considered the source content, not the
classpath, causing NoSuchMethodError when cached classes referenced
methods that no longer exist.

This fix includes a hash of SNAPSHOT and -bin- jars (including their
modification times) in the cache key. When these jars change, the build
definition is recompiled.

Fixes #7713
2026-01-11 21:01:05 -05:00
eugene yokota 4606c90f69
[2.x] ci: Integrate launcher package (#8485)
**Problem/Solution**
This is a follow up to launcher package migrating to sbt 1.x.
This joins the launcher package into the main build.
2026-01-11 20:57:59 -05:00
xuwei-k e5d05ca584 Update mimaPreviousArtifacts and mimaBinaryIssueFilters 2026-01-12 10:31:21 +09:00
xuwei-k d3f7f6bf90 Add test for 8458 2026-01-12 10:03:00 +09:00
byteforge bd03184cf5
[2.x] Fix ProjectMatrix invalid project ID with CrossVersion.full (#8484)
When using `ProjectMatrix` with `CrossVersion.full` and Scala 2 versions like `2.13.18`, the project ID incorrectly became `$1$2_13_18` instead of `foo2_13_18`.

**Root cause:** The Scala 3 compiler creates synthetic intermediate vals (e.g., `$1`) during macro expansion. The `enclosingTerm` function in the macros was stopping at these synthetic symbols instead of continuing up the symbol tree to find the actual val name.

**Fix:** Added `Flags.Synthetic` check to skip compiler-generated symbols in:
- `main-settings/src/main/scala/sbt/std/KeyMacro.scala`
- `lm-core/src/main/scala/sbt/librarymanagement/ConfigurationExtra.scala`

---------

Co-authored-by: byteforge38 <joseph.mc0803@gmail.com>
2026-01-11 19:17:26 -05:00
xuwei-k 813078695f Avoid deprecated java.net.URL constructor
- https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/URL.html#%3Cinit%3E(java.lang.String)
- https://bugs.openjdk.org/browse/JDK-8295949
2026-01-12 08:46:04 +09:00
MkDev11 4fba87a757
fix: Filter out JAR paths in BSP diagnostics on Windows (#8482)
When Java compiler generates warnings about missing annotations from
JAR files, the path format is jar:file:///C:/... which causes
InvalidPathException on Windows due to the : character.

The fix filters out jar: paths in toDocument(), similar to how fake
positions like <macro> are already filtered out. This prevents the
exception and allows compilation to continue.

Diagnostics for files inside JARs are not shown in the IDE, which is
correct behavior since they cannot be edited.

Fixes #7665

Generated-by: Cascade (AI pair programmer)
2026-01-11 16:37:13 -05:00