Skip to content

Commit 2695330

Browse files
committed
improve Scala 2 vs 3 cross-compilation scalac options
1 parent 7ef48cb commit 2695330

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

build.sbt

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,26 @@ startYear := Some(2023)
1010

1111
crossScalaVersions := Seq("2.13.16", "3.3.6")
1212
scalaVersion := crossScalaVersions.value.head
13-
scalacOptions := Seq(
14-
"-release:17",
15-
"-Xsource:3",
16-
"-deprecation",
13+
scalacOptions := crossSettings(
14+
scalaVersion = scalaVersion.value,
15+
if2 = Seq(
16+
"-Xsource:3",
17+
),
18+
// Good compiler options for Scala 2.13 are coming from com.evolution:sbt-scalac-opts-plugin:0.0.9,
19+
// but its support for Scala 3 is limited, especially what concerns linting options.
20+
//
21+
// If Scala 3 is made the primary target, good linting scalac options for it should be added first.
22+
if3 = Seq(
23+
"-Ykind-projector:underscores",
24+
25+
// disable new brace-less syntax:
26+
// https://alexn.org/blog/2022/10/24/scala-3-optional-braces/
27+
"-no-indent",
28+
29+
// improve error messages:
30+
"-explain",
31+
"-explain-types",
32+
),
1733
)
1834
autoAPIMappings := true
1935
versionScheme := Some("early-semver")
@@ -27,6 +43,13 @@ libraryDependencies ++= Seq(
2743

2844
licenses := Seq(("MIT", url("https://opensource.org/licenses/MIT")))
2945

46+
def crossSettings[T](scalaVersion: String, if3: T, if2: T): T = {
47+
scalaVersion match {
48+
case version if version.startsWith("3") => if3
49+
case _ => if2
50+
}
51+
}
52+
3053
addCommandAlias("fmt", "all scalafmtAll scalafmtSbt")
3154
addCommandAlias("check", "all versionPolicyCheck scalafmtCheckAll scalafmtSbtCheck")
3255
addCommandAlias("build", "all compile test")

0 commit comments

Comments
 (0)