Skip to content

Commit d973d11

Browse files
committed
Migrate to sbt 2
Now that sbt-jcheckstyle 0.3.0 publishes an sbt2 cross-build, the sbt2 migration (superseding scala-steward PR #997) is unblocked. Bumps: - sbt: 1.12.13 -> 2.0.1 - sbt-jcheckstyle: 0.2.1 -> 0.3.0 (the actual blocker) - sbt-osgi: 0.10.0 -> 0.11.0-RC1 (only version with an sbt2 cross-build) - sbt-pgp, sbt-scalafmt, sbt-dynver already cross-built for sbt2 at their current versions build.sbt changes required by sbt 2's new task engine: - Wrap the jcheckStyle-dependsOn compile overrides in Def.uncached(...); CompileAnalysis has no JsonFormat to cache against - Add implicitConversions import and method-call dependsOn syntax to clear new Scala 3.8 strictness warnings sbt 2 itself requires JDK 17+ to run, while CI still needs to verify the library at runtime on JDK 8/11/17/21/24. Decouple the two via Test/fork + Test/javaHome (driven by a TEST_JAVA_HOME env var), and update CI.yml/release.yml/snapshot.yml to install a fixed modern JDK to launch sbt itself while forking tests onto the matrix JDK. Published bytecode is unaffected since it's already pinned to 1.8 via javacOptions.
1 parent ed9dd9c commit d973d11

6 files changed

Lines changed: 38 additions & 11 deletions

File tree

.github/workflows/CI.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ jobs:
4040
if: ${{ needs.changes.outputs.code == 'true' }}
4141
steps:
4242
- uses: actions/checkout@v6
43+
# sbt 2 requires JDK 17+ to run
44+
- uses: actions/setup-java@v5
45+
with:
46+
distribution: 'zulu'
47+
java-version: '21'
4348
- name: jcheckstyle
4449
run: ./sbt jcheckStyle
4550
- name: scalafmtCheckAll
4651
run: ./sbt scalafmtCheckAll
47-
52+
4853
test:
4954
name: Test JDK${{ matrix.java }}
5055
runs-on: ubuntu-latest
@@ -55,16 +60,29 @@ jobs:
5560
java: ['8', '11', '17', '21', '24']
5661
steps:
5762
- uses: actions/checkout@v6
63+
# The JDK under test: msgpack-core forks its tests onto this JDK (via
64+
# TEST_JAVA_HOME) so we still verify runtime behavior on each target JDK.
5865
- uses: actions/setup-java@v5
66+
id: target-jdk
5967
with:
6068
distribution: 'zulu'
6169
java-version: ${{ matrix.java }}
70+
# sbt 2 itself requires JDK 17+ to run, so install a fixed, newer JDK to
71+
# actually launch sbt. This becomes the default JDK on PATH/JAVA_HOME.
72+
- uses: actions/setup-java@v5
73+
with:
74+
distribution: 'zulu'
75+
java-version: '21'
6276
- uses: actions/cache@v5
6377
with:
6478
path: ~/.cache
6579
key: ${{ runner.os }}-jdk${{ matrix.java }}-${{ hashFiles('**/*.sbt') }}
6680
restore-keys: ${{ runner.os }}-jdk${{ matrix.java }}-
6781
- name: Test
82+
env:
83+
TEST_JAVA_HOME: ${{ steps.target-jdk.outputs.path }}
6884
run: ./sbt test
6985
- name: Universal Buffer Test
86+
env:
87+
TEST_JAVA_HOME: ${{ steps.target-jdk.outputs.path }}
7088
run: ./sbt test -J-Dmsgpack.universal-buffer=true

.github/workflows/release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ jobs:
1616
fetch-depth: 10000
1717
# Fetch all tags so that sbt-dynver can find the previous release version
1818
- run: git fetch --tags -f
19-
# Install OpenJDK 8
19+
# sbt 2 requires JDK 17+ to run. Android compatibility (originally JDK8,
20+
# see https://github.com/msgpack/msgpack-java/issues/516) is enforced
21+
# independently via the -source/-target 1.8 javacOptions in build.sbt.
2022
- uses: actions/setup-java@v5
2123
with:
22-
# We need to use JDK8 for Android compatibility https://github.com/msgpack/msgpack-java/issues/516
23-
java-version: 8
24+
java-version: 21
2425
distribution: adopt
2526
- name: Setup GPG
2627
env:

.github/workflows/snapshot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ jobs:
2121
fetch-depth: 10000
2222
# Fetch all tags so that sbt-dynver can find the previous release version
2323
- run: git fetch --tags
24+
# sbt 2 requires JDK 17+ to run; published bytecode still targets 1.8
25+
# via the javacOptions in build.sbt.
2426
- uses: actions/setup-java@v5
2527
with:
26-
java-version: 11
28+
java-version: 21
2729
distribution: adopt
2830
- name: Publish snapshots
2931
env:

build.sbt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import scala.language.implicitConversions
2+
13
Global / onChangedBuildSource := ReloadOnSourceChanges
24

35
// For performance testing, ensure each test run one-by-one
@@ -69,6 +71,11 @@ val buildSettings = Seq[Setting[?]](
6971
// JVM options for building
7072
scalacOptions ++= Seq("-encoding", "UTF-8", "-deprecation", "-unchecked", "-feature"),
7173
Test / javaOptions ++= Seq("-ea"),
74+
// sbt 2 itself requires JDK 17+ to run, but CI still needs to verify the library at
75+
// runtime against older JDKs (e.g. 8). Fork tests so they can run on a JDK specified
76+
// via TEST_JAVA_HOME, independent of the JDK running sbt.
77+
Test / fork := true,
78+
Test / javaHome := sys.env.get("TEST_JAVA_HOME").map(file),
7279
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
7380
Compile / compile / javacOptions ++=
7481
Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation"),
@@ -92,8 +99,8 @@ val buildSettings = Seq[Setting[?]](
9299
// Style check config: (sbt-jchekcstyle)
93100
jcheckStyleConfig := "facebook",
94101
// Run jcheckstyle both for main and test codes
95-
Compile / compile := ((Compile / compile) dependsOn (Compile / jcheckStyle)).value,
96-
Test / compile := ((Test / compile) dependsOn (Test / jcheckStyle)).value
102+
Compile / compile := Def.uncached((Compile / compile).dependsOn(Compile / jcheckStyle).value),
103+
Test / compile := Def.uncached((Test / compile).dependsOn(Test / jcheckStyle).value)
97104
)
98105

99106
val junitJupiter = "org.junit.jupiter" % "junit-jupiter" % "5.14.4" % "test"
@@ -134,7 +141,6 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
134141
"--add-opens=java.base/java.nio=ALL-UNNAMED",
135142
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"
136143
),
137-
Test / fork := true,
138144
libraryDependencies ++=
139145
Seq(
140146
// msgpack-core should have no external dependencies

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sbt.version=1.12.13
1+
sbt.version=2.0.1
22

project/plugins.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
22
// TODO: Fixes jacoco error:
33
// java.lang.NoClassDefFoundError: Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter
44
//addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.3.0")
5-
addSbtPlugin("org.xerial.sbt" % "sbt-jcheckstyle" % "0.2.1")
6-
addSbtPlugin("com.github.sbt" % "sbt-osgi" % "0.10.0")
5+
addSbtPlugin("org.xerial.sbt" % "sbt-jcheckstyle" % "0.3.0")
6+
addSbtPlugin("com.github.sbt" % "sbt-osgi" % "0.11.0-RC1")
77
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.6.1")
88
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.1")
99

0 commit comments

Comments
 (0)