From 76fc366d065f30dc80e3ba268d2a98bdfcbd5430 Mon Sep 17 00:00:00 2001 From: the-ivii Date: Tue, 24 Feb 2026 12:18:55 +0530 Subject: [PATCH] feat: sbt-2 migration prototype with ProjectMatrixWrapper and thin client --- .../typelevel/sbt/ProjectMatrixWrapper.scala | 37 +++++++++++++++++++ .../org/typelevel/sbt/TypelevelCiPlugin.scala | 2 +- .../typelevel/sbt/gha/GenerativePlugin.scala | 4 +- project/build.properties | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 ci/src/main/scala/org/typelevel/sbt/ProjectMatrixWrapper.scala diff --git a/ci/src/main/scala/org/typelevel/sbt/ProjectMatrixWrapper.scala b/ci/src/main/scala/org/typelevel/sbt/ProjectMatrixWrapper.scala new file mode 100644 index 00000000..30bfaab9 --- /dev/null +++ b/ci/src/main/scala/org/typelevel/sbt/ProjectMatrixWrapper.scala @@ -0,0 +1,37 @@ +package org.typelevel.sbt + +import sbt._ +import sbtprojectmatrix.ProjectMatrix // sbt‑2 API + +/** Compatibility shim – keeps the old API but uses ProjectMatrix under the hood. */ +@deprecated("CrossRootProject is deprecated – use sbt‑2 ProjectMatrix directly.", "0.6.0") +final class CrossRootProject private (val matrix: ProjectMatrix) extends CompositeProject { + def all = matrix.project("all") + def jvm = matrix.project("jvm") + def js = matrix.project("js") + def native = matrix.project("native") + + override def componentProjects: Seq[Project] = Seq(all, jvm, js, native) + + def settings(ss: Def.SettingsDefinition*): CrossRootProject = new CrossRootProject(matrix.settings(ss: _*)) + def configure(transforms: (Project => Project)*): CrossRootProject = this + def configureRoot(transforms: (Project => Project)*): CrossRootProject = this + def configureJVM(transforms: (Project => Project)*): CrossRootProject = this + def configureJS(transforms: (Project => Project)*): CrossRootProject = this + def configureNative(transforms: (Project => Project)*): CrossRootProject = this + def enablePlugins(ns: Plugins*): CrossRootProject = new CrossRootProject(matrix.enablePlugins(ns: _*)) + def disablePlugins(ps: AutoPlugin*): CrossRootProject = new CrossRootProject(matrix.disablePlugins(ps: _*)) + def aggregate(projects: CompositeProject*): CrossRootProject = this +} + +object CrossRootProject { + /** Factory used by the existing macro (we’ll drop the macro later). */ + def apply(id: String): CrossRootProject = { + val pm = ProjectMatrix(id) + .jvm( Project(id + "JVM", file(".jvm")) ) + .js( Project(id + "JS", file(".js")) ) + .native(Project(id + "Native",file(".native"))) + .all( Project(id + "All", file("."))) + new CrossRootProject(pm) + } +} diff --git a/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala b/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala index 877fa5f3..711a0f2f 100644 --- a/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala +++ b/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala @@ -31,7 +31,7 @@ object TypelevelCiPlugin extends AutoPlugin { override def trigger = allRequirements object autoImport { - def tlCrossRootProject: CrossRootProject = macro CrossRootProjectMacros.crossRootProjectImpl + def tlCrossRootProject: CrossRootProject = CrossRootProject("myproj") lazy val tlCiHeaderCheck = settingKey[Boolean]("Whether to do header check in CI (default: false)") diff --git a/github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativePlugin.scala b/github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativePlugin.scala index 5b6188c0..15c84fcd 100644 --- a/github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativePlugin.scala +++ b/github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativePlugin.scala @@ -656,7 +656,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} githubWorkflowIncludeClean := true, // This is currently set to false because of https://github.com/sbt/sbt/issues/6468. When a new SBT version is // released that fixes this issue then check for that SBT version (or higher) and set to true. - githubWorkflowUseSbtThinClient := false, + githubWorkflowUseSbtThinClient := true, githubWorkflowConcurrency := Some( Concurrency( group = s"$${{ github.workflow }} @ $${{ github.ref }}", @@ -670,7 +670,7 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)} githubWorkflowBuildTimeoutMinutes := Some(60), githubWorkflowBuildPreamble := Seq(), githubWorkflowBuildPostamble := Seq(), - githubWorkflowBuildSbtStepPreamble := Seq(s"++ $${{ matrix.scala }}"), + githubWorkflowBuildSbtStepPreamble := Nil, githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("test"), name = Some("Build project"))), githubWorkflowPublishPreamble := Seq(), githubWorkflowPublishPostamble := Seq(), diff --git a/project/build.properties b/project/build.properties index 01a16ed1..f8d382d0 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.11.7 +sbt.version=2.0.0-M2