[2.x] Fallback to HOME/.config/sbt (#8780)

**Problem/Solution**
When XDG_CONFIG_HOME is not defined, we should fallback to HOME/.config/sbt.
This commit is contained in:
eugene yokota 2026-02-22 00:02:30 -05:00 committed by GitHub
parent 861fbccaea
commit b1bfb6e627
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -207,11 +207,12 @@ object SysProp:
/**
* Default directory for global sbt config (plugins, settings). Respects XDG Base Directory
* and platform conventions: SBT_CONFIG_HOME, then XDG_CONFIG_HOME/sbt (Unix), then
* LOCALAPPDATA/sbt (Windows), else user.home/.sbt.
* LOCALAPPDATA/sbt (Windows), else user.home/.config/sbt.
*/
def defaultGlobalBaseDirectory: File =
def fromEnv(name: String): Option[File] =
sys.env.get(name).filter(_.nonEmpty).map(p => file(p.trim))
def fallbackDir: File = home / ".config" / "sbt"
val propBase =
sys.props.get(BuildPaths.GlobalBaseProperty).filter(_.nonEmpty).map(p => file(p.trim))
propBase
@ -220,7 +221,7 @@ object SysProp:
if Util.isWindows then fromEnv("LOCALAPPDATA").map(_ / "sbt")
else fromEnv("XDG_CONFIG_HOME").map(_ / "sbt")
)
.getOrElse(home / BuildPaths.ConfigDirectoryName)
.getOrElse(fallbackDir)
.getAbsoluteFile
/**

2
sbt
View File

@ -645,7 +645,7 @@ Usage: `basename "$0"` [options]
--jvm-client run JVM client
--timings display task timings report on shutdown
--allow-empty start sbt even if current directory contains no sbt project
--sbt-dir <path> path to global settings/plugins directory (default: \$XDG_CONFIG_HOME/sbt or ~/.sbt)
--sbt-dir <path> path to global settings/plugins directory (default: \$XDG_CONFIG_HOME/sbt or ~/.config/sbt)
--sbt-boot <path> path to shared boot directory (default: ~/.sbt/boot in 0.11 series)
--sbt-cache <path> path to global cache directory (default: operating system specific)
--ivy <path> path to local Ivy repository (default: ~/.ivy2)