This is an automated email from the ASF dual-hosted git repository.

pjfanning pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-grpc.git


The following commit(s) were added to refs/heads/main by this push:
     new f158a8af update sbt plugin to support sbt1 and sbt2 (#710)
f158a8af is described below

commit f158a8af027fa9de9291c8e949d77e4ef8e3beb2
Author: PJ Fanning <[email protected]>
AuthorDate: Fri May 29 17:26:31 2026 +0100

    update sbt plugin to support sbt1 and sbt2 (#710)
    
    * Add sbt1/sbt2 cross-build support for sbt-plugin
    
    * some build issues
    
    * Fix Scala 3 compilation errors in sbt-plugin
    
    * Update PekkoGrpcPlugin.scala
    
    * Replace inTask(PB.recompile)(...) with explicit PB.recompile / key 
scoping for sbt 2.x/Scala 3 compat
    
    * Use sbt2-compat Def.uncached for watchSources to fix Scala 3.8/sbt 2.x 
caching error
    
    * Fix Scala 2.12 type mismatch in watchSources: map File to WatchSource
    
    * Update Common.scala
    
    * scalafmt
    
    * Update build.sbt
    
    * Update build.sbt
    
    * Update build.sbt
    
    * Update build.sbt
    
    * Fix watchSources override and inConfig scoping for PB.recompile settings
    
    ---------
    
    Co-authored-by: copilot-swe-agent[bot] 
<[email protected]>
---
 build.sbt                                          | 19 +++++-
 project/Common.scala                               |  3 +-
 project/Dependencies.scala                         |  3 +-
 project/plugins.sbt                                |  2 +-
 .../apache/pekko/grpc/sbt/GeneratorBridge.scala    |  2 +-
 .../apache/pekko/grpc/sbt/PekkoGrpcPlugin.scala    | 69 ++++++++++++----------
 .../src/sbt-test/scala3/03-sbt2-basic/build.sbt    | 14 +++++
 .../scala3/03-sbt2-basic/project/plugins.sbt       | 10 ++++
 .../03-sbt2-basic/src/main/protobuf/echo.proto     | 20 +++++++
 sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/test  |  1 +
 10 files changed, 103 insertions(+), 40 deletions(-)

diff --git a/build.sbt b/build.sbt
index 28e7b26d..477c60e4 100644
--- a/build.sbt
+++ b/build.sbt
@@ -81,7 +81,7 @@ lazy val codegen = Project(id = "codegen", base = 
file("codegen"))
       case _                                                        => 
MergeStrategy.deduplicate
     },
     crossScalaVersions := Dependencies.Versions.CrossScalaForPlugin,
-    scalaVersion := scala212)
+    scalaVersion := Dependencies.Versions.CrossScalaForPlugin.head)
   .settings(addArtifact(Compile / assembly / artifact, assembly))
   .settings(addArtifact(sbt.Artifact(pekkoGrpcCodegenId, "bat", "bat", "bat"), 
mkBatAssemblyTask))
 
@@ -168,7 +168,15 @@ lazy val sbtPlugin = Project(id = "sbt-plugin", base = 
file("sbt-plugin"))
   .settings(
     name := s"$pekkoPrefix-sbt-plugin",
     sbtPluginPublishLegacyMavenStyle := true,
+    addSbtPlugin("com.github.sbt" % "sbt2-compat" % "0.1.0"),
+    pluginCrossBuild / sbtVersion := {
+      scalaBinaryVersion.value match {
+        case "2.12" => "1.12.11"
+        case _      => "2.0.0-RC13"
+      }
+    },
     /** And for scripted tests: */
+    scriptedSbt := (pluginCrossBuild / sbtVersion).value,
     scriptedLaunchOpts += ("-Dproject.version=" + version.value),
     scriptedLaunchOpts ++= sys.props.collect { case (k @ "sbt.ivy.home", v) => 
s"-D$k=$v" }.toSeq,
     scriptedDependencies := {
@@ -177,8 +185,13 @@ lazy val sbtPlugin = Project(id = "sbt-plugin", base = 
file("sbt-plugin"))
       val p3 = (runtime / publishLocal).value
       val p4 = (interopTests / publishLocal).value
     },
-    scriptedSbt := "1.12.11",
-    scriptedBufferLog := false)
+    scriptedBufferLog := false,
+    scalacOptions ++= {
+      scalaBinaryVersion.value match {
+        case "2.12" => Seq("-Xsource:3")
+        case _      => Seq.empty
+      }
+    })
   .settings(
     crossScalaVersions := Dependencies.Versions.CrossScalaForPlugin,
     scalaVersion := Dependencies.Versions.CrossScalaForPlugin.head)
diff --git a/project/Common.scala b/project/Common.scala
index 82ba63cc..3b1f7218 100644
--- a/project/Common.scala
+++ b/project/Common.scala
@@ -57,8 +57,7 @@ object Common extends AutoPlugin {
          Seq(
            "-unchecked",
            "-deprecation",
-           "-language:_",
-           "-Xfatal-warnings",
+           "-Werror",
            "-Wunused:imports",
            "-encoding",
            "UTF-8")),
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index a5fc442c..10e6dc51 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -19,10 +19,11 @@ object Dependencies {
     val scala212 = "2.12.21"
     val scala213 = "2.13.18"
     val scala3 = "3.3.7"
+    val scala3_8 = "3.8.3"
 
     // the order in the list is important because the head will be considered 
the default.
     val CrossScalaForLib = Seq(scala213, scala3)
-    val CrossScalaForPlugin = Seq(scala212)
+    val CrossScalaForPlugin = Seq(scala212, scala3_8)
     val CrossScalaAll = Seq(scala212, scala213, scala3)
 
     // We don't force Pekko updates because downstream projects can upgrade
diff --git a/project/plugins.sbt b/project/plugins.sbt
index bba78a03..a6be7501 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -9,7 +9,7 @@
 
 enablePlugins(BuildInfoPlugin)
 
-val sbtProtocV = "1.0.8"
+val sbtProtocV = "1.1.0-RC1"
 
 buildInfoKeys := Seq[BuildInfoKey]("sbtProtocVersion" -> sbtProtocV)
 
diff --git 
a/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/GeneratorBridge.scala 
b/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/GeneratorBridge.scala
index 13da7e15..7334a285 100644
--- a/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/GeneratorBridge.scala
+++ b/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/GeneratorBridge.scala
@@ -26,7 +26,7 @@ object GeneratorBridge {
       logger: Logger): protocbridge.Generator = {
     // This matches the sbt binary version (2.12)
     val codegenScalaBinaryVersion = 
CrossVersion.binaryScalaVersion(BuildInfo.scalaVersion)
-    protocbridge.SandboxedJvmGenerator(
+    protocbridge.SandboxedJvmGenerator.forResolver(
       codeGenerator.name,
       protocbridge.Artifact(BuildInfo.organization, 
s"${BuildInfo.name}_$codegenScalaBinaryVersion", BuildInfo.version),
       codeGenerator.suggestedDependencies(scalaBinaryVersion),
diff --git 
a/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/PekkoGrpcPlugin.scala 
b/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/PekkoGrpcPlugin.scala
index cbb06e77..553b78dd 100644
--- a/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/PekkoGrpcPlugin.scala
+++ b/sbt-plugin/src/main/scala/org/apache/pekko/grpc/sbt/PekkoGrpcPlugin.scala
@@ -21,11 +21,10 @@ import pekko.grpc.gen.{ BuildInfo, Logger => GenLogger, 
ProtocSettings }
 import protocbridge.Generator
 import sbt.Keys._
 import sbt._
+import sbtcompat.PluginCompat._
 import sbtprotoc.ProtocPlugin
 import scalapb.ScalaPbCodeGenerator
 
-import language.implicitConversions
-
 object PekkoGrpcPlugin extends AutoPlugin {
   import sbtprotoc.ProtocPlugin.autoImport._
 
@@ -35,25 +34,22 @@ object PekkoGrpcPlugin extends AutoPlugin {
 
   // hack because we cannot access sbt logger from streams unless inside 
taskKeys and
   // we need it in settingsKeys
-  private val generatorLogger = new GenLogger {
+  private class MutableLogger extends GenLogger {
     @volatile var logger: Logger = ConsoleLogger()
     def debug(text: String): Unit = logger.debug(text)
     def info(text: String): Unit = logger.info(text)
     def warn(text: String): Unit = logger.warn(text)
     def error(text: String): Unit = logger.error(text)
   }
+  private val generatorLogger = new MutableLogger
 
-  object GeneratorOption extends Enumeration {
-    protected case class Val(setting: String) extends super.Val
-    implicit def valueToGeneratorOptionVal(x: Value): Val = x.asInstanceOf[Val]
-
-    val ServerPowerApis = Val("server_power_apis")
-    val UsePlayActions = Val("use_play_actions")
-
-    val settings: Set[String] = values.map(_.setting)
+  object GeneratorOption {
+    val ServerPowerApis = "server_power_apis"
+    val UsePlayActions = "use_play_actions"
+    val settings: Set[String] = Set(ServerPowerApis, UsePlayActions)
   }
 
-  trait Keys { _: autoImport.type =>
+  trait Keys { self: autoImport.type =>
 
     object PekkoGrpc {
       sealed trait GeneratedSource
@@ -86,7 +82,7 @@ object PekkoGrpcPlugin extends AutoPlugin {
   object autoImport extends Keys
   import autoImport._
 
-  override def projectSettings: Seq[sbt.Setting[_]] = defaultSettings ++ 
configSettings(Compile) ++ configSettings(Test)
+  override def projectSettings: Seq[sbt.Setting[?]] = defaultSettings ++ 
configSettings(Compile) ++ configSettings(Test)
 
   private def defaultSettings =
     Seq(
@@ -113,7 +109,7 @@ object PekkoGrpcPlugin extends AutoPlugin {
       },
       PB.protocVersion := BuildInfo.googleProtocVersion)
 
-  def configSettings(config: Configuration): Seq[Setting[_]] =
+  def configSettings(config: Configuration): Seq[Setting[?]] =
     inConfig(config)(
       (if (config == Compile || config == Test) Seq() // already supported by 
sbt-protoc by default
        else sbtprotoc.ProtocPlugin.protobufConfigSettings) ++
@@ -122,7 +118,9 @@ object PekkoGrpcPlugin extends AutoPlugin {
           configuration.value.name),
         managedSourceDirectories += (pekkoGrpcCodeGeneratorSettings / 
target).value,
         unmanagedResourceDirectories ++= (PB.recompile / 
resourceDirectories).value,
-        Defaults.ConfigGlobal / watchSources ++= (PB.recompile / 
sources).value,
+        Defaults.ConfigZero / watchSources ++= Def.uncached {
+          (PB.recompile / sources).value.map(f => WatchSource(f))
+        },
         pekkoGrpcGenerators := {
           generatorsFor(
             pekkoGrpcGeneratedSources.value,
@@ -137,23 +135,30 @@ object PekkoGrpcPlugin extends AutoPlugin {
             (pekkoGrpcCodeGeneratorSettings / target).value,
             pekkoGrpcCodeGeneratorSettings.value,
             pekkoGrpcGenerators.value),
-        PB.protoSources += sourceDirectory.value / "proto") ++
-      inTask(PB.recompile)(Seq(
-        includeFilter := GlobFilter("*.proto"),
-        managedSourceDirectories := Nil,
-        unmanagedSourceDirectories := Seq(sourceDirectory.value),
-        sourceDirectories := unmanagedSourceDirectories.value ++ 
managedSourceDirectories.value,
-        managedSources := Nil,
-        unmanagedSources := { 
Defaults.collectFiles(unmanagedSourceDirectories, includeFilter, 
excludeFilter).value },
-        sources := managedSources.value ++ unmanagedSources.value,
-        managedResourceDirectories := Nil,
-        unmanagedResourceDirectories := resourceDirectory.value +: 
PB.protoSources.value,
-        resourceDirectories := unmanagedResourceDirectories.value ++ 
managedResourceDirectories.value,
-        managedResources := Nil,
-        unmanagedResources := {
-          Defaults.collectFiles(unmanagedResourceDirectories, includeFilter, 
excludeFilter).value
-        },
-        resources := managedResources.value ++ unmanagedResources.value)))
+        PB.protoSources += sourceDirectory.value / "proto")) ++
+    inConfig(config)(Seq(
+      PB.recompile / includeFilter := GlobFilter("*.proto"),
+      PB.recompile / managedSourceDirectories := Nil,
+      PB.recompile / unmanagedSourceDirectories := Seq(sourceDirectory.value),
+      PB.recompile / sourceDirectories := (PB.recompile / 
unmanagedSourceDirectories).value ++
+      (PB.recompile / managedSourceDirectories).value,
+      PB.recompile / managedSources := Nil,
+      PB.recompile / unmanagedSources := {
+        Defaults.collectFiles(PB.recompile / unmanagedSourceDirectories, 
PB.recompile / includeFilter,
+          PB.recompile / excludeFilter).value
+      },
+      PB.recompile / sources := (PB.recompile / managedSources).value ++ 
(PB.recompile / unmanagedSources).value,
+      PB.recompile / managedResourceDirectories := Nil,
+      PB.recompile / unmanagedResourceDirectories := resourceDirectory.value 
+: PB.protoSources.value,
+      PB.recompile / resourceDirectories := (PB.recompile / 
unmanagedResourceDirectories).value ++
+      (PB.recompile / managedResourceDirectories).value,
+      PB.recompile / managedResources := Nil,
+      PB.recompile / unmanagedResources := {
+        Defaults.collectFiles(PB.recompile / unmanagedResourceDirectories, 
PB.recompile / includeFilter,
+          PB.recompile / excludeFilter).value
+      },
+      PB.recompile / resources := (PB.recompile / managedResources).value ++
+      (PB.recompile / unmanagedResources).value))
 
   def targetsFor(
       targetPath: File,
diff --git a/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/build.sbt 
b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/build.sbt
new file mode 100644
index 00000000..8509801e
--- /dev/null
+++ b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/build.sbt
@@ -0,0 +1,14 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+// Verify that the pekko-grpc sbt plugin cross-builds correctly for sbt 1.x 
and sbt 2.x.
+// When run in the Scala 3 build pass (+scripted), scriptedSbt is set to 2.x.y.
+scalaVersion := "3.3.7"
+
+enablePlugins(PekkoGrpcPlugin)
diff --git a/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/project/plugins.sbt 
b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/project/plugins.sbt
new file mode 100644
index 00000000..5eb2b655
--- /dev/null
+++ b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/project/plugins.sbt
@@ -0,0 +1,10 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+addSbtPlugin("org.apache.pekko" % "pekko-grpc-sbt-plugin" % 
sys.props("project.version"))
diff --git 
a/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/src/main/protobuf/echo.proto 
b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/src/main/protobuf/echo.proto
new file mode 100644
index 00000000..1e4a2075
--- /dev/null
+++ b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/src/main/protobuf/echo.proto
@@ -0,0 +1,20 @@
+syntax = "proto3";
+
+option java_multiple_files = true;
+option java_package = "example.myapp.echo.grpc";
+option java_outer_classname = "EchoProto";
+
+package echo;
+
+// Simple echo service used to verify sbt-plugin code generation under sbt 2.
+service EchoService {
+    rpc Echo (EchoRequest) returns (EchoReply) {}
+}
+
+message EchoRequest {
+    string message = 1;
+}
+
+message EchoReply {
+    string message = 1;
+}
diff --git a/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/test 
b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/test
new file mode 100644
index 00000000..5df2af1f
--- /dev/null
+++ b/sbt-plugin/src/sbt-test/scala3/03-sbt2-basic/test
@@ -0,0 +1 @@
+> compile


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to