From fd850e2f2b8c0b6acf262cd4197b9fb96a7d76c8 Mon Sep 17 00:00:00 2001 From: Roman Langolf Date: Sat, 20 Jun 2026 13:20:28 +0700 Subject: [PATCH 1/2] Update to sbt 2.0.0 and cross-publish plugin for sbt 1.x and 2.x --- build.sbt | 14 +++++-- .../gar/ArtifactRegistryIvyRepository.scala | 0 .../dev/rolang/sbt/gar/GarCompat.scala | 39 +++++++++++++++++++ .../dev/rolang/sbt/gar/GarCompat.scala | 35 +++++++++++++++++ .../scala/dev/rolang/sbt/gar/GarPlugin.scala | 33 +--------------- project/build.properties | 2 +- 6 files changed, 87 insertions(+), 36 deletions(-) rename modules/sbt/src/main/{scala => scala-2.12}/dev/rolang/sbt/gar/ArtifactRegistryIvyRepository.scala (100%) create mode 100644 modules/sbt/src/main/scala-2.12/dev/rolang/sbt/gar/GarCompat.scala create mode 100644 modules/sbt/src/main/scala-3/dev/rolang/sbt/gar/GarCompat.scala diff --git a/build.sbt b/build.sbt index 100b940..379493b 100644 --- a/build.sbt +++ b/build.sbt @@ -21,9 +21,12 @@ ThisBuild / versionScheme := Some("early-semver") lazy val scala213 = "2.13.18" lazy val scala212 = "2.12.21" +lazy val scala3 = "3.8.4" ThisBuild / scalaVersion := scala213 +ThisBuild / allowMismatchScala := true + lazy val commonSettings = List( publishTo := { val centralSnapshots = "https://central.sonatype.com/repository/maven-snapshots/" @@ -34,7 +37,6 @@ lazy val commonSettings = List( ) lazy val root = (project in file(".")) - .dependsOn(core, coursier, plugin) .aggregate(core, coursier, plugin) .settings( name := "gar-handler", @@ -55,7 +57,7 @@ lazy val core = project .settings( moduleName := "gar-handler", scalaVersion := scala212, - crossScalaVersions := Seq(scala212, scala213), + crossScalaVersions := Seq(scala212, scala213, scala3), Compile / sourceGenerators += Def.task { val file = (Compile / sourceManaged).value / "dev" / "rolang" / "gar" / "version.scala" val contents = version.value @@ -94,7 +96,13 @@ lazy val plugin = project .settings( moduleName := "sbt-gar-handler", scalaVersion := scala212, - crossScalaVersions := Seq(scala212), + crossScalaVersions := Seq(scala212, scala3), + pluginCrossBuild / sbtVersion := { + scalaBinaryVersion.value match { + case "2.12" => "1.12.11" + case _ => "2.0.0" + } + }, sbtPluginPublishLegacyMavenStyle := false, scriptedLaunchOpts := { scriptedLaunchOpts.value ++ diff --git a/modules/sbt/src/main/scala/dev/rolang/sbt/gar/ArtifactRegistryIvyRepository.scala b/modules/sbt/src/main/scala-2.12/dev/rolang/sbt/gar/ArtifactRegistryIvyRepository.scala similarity index 100% rename from modules/sbt/src/main/scala/dev/rolang/sbt/gar/ArtifactRegistryIvyRepository.scala rename to modules/sbt/src/main/scala-2.12/dev/rolang/sbt/gar/ArtifactRegistryIvyRepository.scala diff --git a/modules/sbt/src/main/scala-2.12/dev/rolang/sbt/gar/GarCompat.scala b/modules/sbt/src/main/scala-2.12/dev/rolang/sbt/gar/GarCompat.scala new file mode 100644 index 0000000..c3af9b3 --- /dev/null +++ b/modules/sbt/src/main/scala-2.12/dev/rolang/sbt/gar/GarCompat.scala @@ -0,0 +1,39 @@ +package dev.rolang.sbt.gar + +import sbt._ +import sbt.Keys._ +import scala.util.{Failure, Success, Try} + +object GarCompat { + def projectSettings: Seq[Def.Setting[_]] = + Seq( + onLoad in Global := (onLoad in Global).value.andThen { state => + val sbtLogger = state.log + val logger = new dev.rolang.gar.Logger { + override def info(msg: String): Unit = sbtLogger.info(msg) + override def error(msg: String): Unit = sbtLogger.err(msg) + override def debug(msg: String): Unit = sbtLogger.debug(msg) + } + + Try { + dev.rolang.gar.ArtifactRegistryUrlHandlerFactory.install(logger) + } match { + case Success(_) => state + case Failure(err) => { + sbtLogger.err( + s"Failed to install artifactregistry handler: ${err}. Publishing/resolving artifacts from Google Artifact Registry is disabled." + ) + state + } + } + }, + csrConfiguration := csrConfiguration.value.withProtocolHandlerDependencies( + Seq("dev.rolang" % "gar-coursier_2.13" % dev.rolang.gar.version.value) + ), + publishTo := publishTo.value.map { + case m: sbt.librarymanagement.MavenRepository if m.root.startsWith("artifactregistry://") => + ArtifactRegistryIvyResolver.create(m.name, m.root) + case other => other + } + ) +} diff --git a/modules/sbt/src/main/scala-3/dev/rolang/sbt/gar/GarCompat.scala b/modules/sbt/src/main/scala-3/dev/rolang/sbt/gar/GarCompat.scala new file mode 100644 index 0000000..aa7581a --- /dev/null +++ b/modules/sbt/src/main/scala-3/dev/rolang/sbt/gar/GarCompat.scala @@ -0,0 +1,35 @@ +package dev.rolang.sbt.gar + +import sbt.* +import sbt.Keys.* +import scala.util.{Failure, Success, Try} + +object GarCompat: + def projectSettings: Seq[Def.Setting[?]] = + Seq( + Global / onLoad := (Global / onLoad).value.andThen { state => + val sbtLogger = state.log + val logger = new dev.rolang.gar.Logger { + override def info(msg: String): Unit = sbtLogger.info(msg) + override def error(msg: String): Unit = sbtLogger.err(msg) + override def debug(msg: String): Unit = sbtLogger.debug(msg) + } + + Try { + dev.rolang.gar.ArtifactRegistryUrlHandlerFactory.install(logger) + } match { + case Success(_) => state + case Failure(err) => { + sbtLogger.err( + s"Failed to install artifactregistry handler: ${err}. Publishing/resolving artifacts from Google Artifact Registry is disabled." + ) + state + } + } + }, + publishTo := publishTo.value.map { + case m: sbt.librarymanagement.MavenRepository if m.root.startsWith("artifactregistry://") => + m + case other => other + } + ) diff --git a/modules/sbt/src/main/scala/dev/rolang/sbt/gar/GarPlugin.scala b/modules/sbt/src/main/scala/dev/rolang/sbt/gar/GarPlugin.scala index bbcce78..43473fb 100644 --- a/modules/sbt/src/main/scala/dev/rolang/sbt/gar/GarPlugin.scala +++ b/modules/sbt/src/main/scala/dev/rolang/sbt/gar/GarPlugin.scala @@ -2,7 +2,6 @@ package dev.rolang.sbt.gar import sbt._ import sbt.Keys._ -import scala.util.{Failure, Success, Try} object GarPlugin extends AutoPlugin { override def trigger = allRequirements @@ -11,35 +10,5 @@ object GarPlugin extends AutoPlugin { import autoImport._ - override def projectSettings: Seq[Def.Setting[_]] = - Seq( - onLoad in Global := (onLoad in Global).value.andThen { state => - val sbtLogger = state.log - val logger = new dev.rolang.gar.Logger { - override def info(msg: String): Unit = sbtLogger.info(msg) - override def error(msg: String): Unit = sbtLogger.err(msg) - override def debug(msg: String): Unit = sbtLogger.debug(msg) - } - - Try { - dev.rolang.gar.ArtifactRegistryUrlHandlerFactory.install(logger) - } match { - case Success(_) => state - case Failure(err) => { - sbtLogger.err( - s"Failed to install artigactregistry handler: ${err}. Publishing/resolving artifacts from Google Artifact Registry is disabled." - ) - state - } - } - }, - csrConfiguration := csrConfiguration.value.withProtocolHandlerDependencies( - Seq("dev.rolang" % "gar-coursier_2.13" % dev.rolang.gar.version.value) - ), - publishTo := publishTo.value.map { - case m: sbt.librarymanagement.MavenRepository if m.root.startsWith("artifactregistry://") => - ArtifactRegistryIvyResolver.create(m.name, m.root) - case other => other - } - ) ++ super.projectSettings + override def projectSettings = GarCompat.projectSettings } diff --git a/project/build.properties b/project/build.properties index dabdb15..666624a 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.12.11 +sbt.version=2.0.0 From 76ed778db647405d309591421c3f4cbdebfab3dd Mon Sep 17 00:00:00 2001 From: Roman Langolf Date: Mon, 13 Jul 2026 13:15:26 +0700 Subject: [PATCH 2/2] update sbt --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index 666624a..312809a 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=2.0.0 +sbt.version=2.0.1