diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5c074b68..9bf27d22e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,12 @@ jobs: sbt --client "scalafmtCheckAll; scalafmtSbtCheck" || \ { echo "[error] Code not formatted prior to commit. Run 'sbt scalafmtAll scalafmtSbt' then commit the reformatted code."; false; } + - name: Run additional validations + run: | + sbt --client "additionalValidation" || \ + { echo "[error] Additional validation failed."; false; } + + - name: sbt shutdown run: | sbt --client shutdown diff --git a/akka-javasdk-maven/akka-javasdk-parent/pom.xml b/akka-javasdk-maven/akka-javasdk-parent/pom.xml index e47e49cdc..17ccf9451 100644 --- a/akka-javasdk-maven/akka-javasdk-parent/pom.xml +++ b/akka-javasdk-maven/akka-javasdk-parent/pom.xml @@ -35,6 +35,8 @@ yyyyMMddHHmmss 3.0.2 + + 2.5.1 21 @@ -425,6 +427,38 @@ + + + generate-protobuf-endpoints + + + src/main/proto + + + + + + com.lightbend.akka.grpc + akka-grpc-maven-plugin + ${akka.grpc.version} + + + + true + + + + + + + generate + + + + + + + @@ -433,25 +467,11 @@ io.akka akka-javasdk ${akka-javasdk.version} - - - - com.lightbend.akka.grpc - akka-grpc-runtime_2.13 - - io.akka akka-javasdk-testkit ${akka-javasdk.version} - - - - com.lightbend.akka.grpc - akka-grpc-runtime_2.13 - - io.kalix diff --git a/project/Common.scala b/project/Common.scala index da8638dda..c98a6e5bd 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -1,12 +1,13 @@ import akka.grpc.sbt.AkkaGrpcPlugin -import sbt.* -import sbt.Keys.* +import sbt._ +import sbt.Keys._ import com.lightbend.sbt.JavaFormatterPlugin.autoImport.javafmtOnCompile import de.heikoseeberger.sbtheader.{ AutomateHeaderPlugin, HeaderPlugin } import org.scalafmt.sbt.ScalafmtPlugin import org.scalafmt.sbt.ScalafmtPlugin.autoImport.scalafmtOnCompile import sbtprotoc.ProtocPlugin +import java.nio.charset.StandardCharsets import scala.collection.breakOut object CommonSettings extends AutoPlugin { @@ -14,6 +15,9 @@ object CommonSettings extends AutoPlugin { override def requires = plugins.JvmPlugin && ScalafmtPlugin override def trigger = allRequirements + val additionalValidation = + taskKey[Unit]("Validation of project specifics that should break the build if invalid") + override def globalSettings = Seq( organization := "io.akka", @@ -47,7 +51,8 @@ object CommonSettings extends AutoPlugin { Compile / scalacOptions ++= Seq("-encoding", "UTF-8", "-deprecation", "-release", "21"), run / javaOptions ++= { sys.props.collect { case (key, value) if key.startsWith("akka") => s"-D$key=$value" }(breakOut) - }) ++ ( + }, + additionalValidation := performAdditionalValidation((ThisBuild / baseDirectory).value)) ++ ( if (sys.props.contains("disable.apidocs")) Seq(Compile / doc / sources := Seq.empty, Compile / packageDoc / publishArtifact := false) else Seq.empty @@ -84,7 +89,21 @@ object CommonSettings extends AutoPlugin { } else Seq.empty } - override def projectSettings = Seq(run / fork := true, Test / fork := true, Test / javaOptions ++= Seq("-Xms1G")) + override def projectSettings = + Seq(run / fork := true, Test / fork := true, Test / javaOptions ++= Seq("-Xms1G")) + + def performAdditionalValidation(projectRoot: File): Unit = { + val pluginVersion = akka.grpc.gen.BuildInfo.version + val parentPomFile = projectRoot / "akka-javasdk-maven" / "akka-javasdk-parent" / "pom.xml" + val parentPomContents = IO.read(parentPomFile, StandardCharsets.UTF_8) + val akkaGrpcVersionRegex = """([0-9.]+)""".r + val parentPomAkkaGrpcVersion = akkaGrpcVersionRegex.findFirstMatchIn(parentPomContents).get.group(1) + if (pluginVersion != parentPomAkkaGrpcVersion) + throw new IllegalStateException( + s"SDK Akka gRPC plugin version is [$pluginVersion] but parent pom version is not the same [$parentPomAkkaGrpcVersion]. " + + s"Align $parentPomFile with the SDK build version to correct.") + } + } object CommonHeaderSettings extends AutoPlugin { diff --git a/project/SamplesCompilationProject.scala b/project/SamplesCompilationProject.scala index 1e20a20f9..cbfb11896 100644 --- a/project/SamplesCompilationProject.scala +++ b/project/SamplesCompilationProject.scala @@ -1,5 +1,6 @@ -import java.io.File +import akka.grpc.sbt.AkkaGrpcPlugin +import java.io.File import de.heikoseeberger.sbtheader.HeaderPlugin import sbt.* import sbt.CompositeProject @@ -23,12 +24,17 @@ object SamplesCompilationProject { Project(id = s"samples", base = file(pathToSample)) .aggregate(innerProjects.map(p => p: ProjectReference): _*) + import akka.grpc.sbt.AkkaGrpcPlugin.autoImport._ lazy val innerProjects = findSamples .map { dir => val proj = Project("sample-" + dir.getName, dir) .disablePlugins(HeaderPlugin) - .settings(Test / unmanagedSourceDirectories += baseDirectory.value / "src" / "it" / "java") + .enablePlugins(AkkaGrpcPlugin) + .settings( + Test / unmanagedSourceDirectories += baseDirectory.value / "src" / "it" / "java", + akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Java), + akkaGrpcCodeGeneratorSettings += "generate_scala_handler_factory") additionalDeps.get(dir.getName).fold(proj)(deps => proj.settings(libraryDependencies ++= deps)) } diff --git a/project/plugins.sbt b/project/plugins.sbt index 097fd094f..915d70e37 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,8 @@ resolvers += "Akka repository".at("https://repo.akka.io/maven") addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1") -// Note: akka-grpc must be carefully kept in sync with the version used in the runtime +// Note: akka-grpc must be carefully kept in sync with the version used in the runtime. +// Whenever this is bumped, akka-javasdk-maven/akka-javasdk-parent/pom.xml must be bumped to the same version addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.5.1") addSbtPlugin("com.lightbend.sbt" % "sbt-java-formatter" % "0.7.0") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") diff --git a/samples/doc-snippets/pom.xml b/samples/doc-snippets/pom.xml index 6f4e148eb..cebd59d07 100644 --- a/samples/doc-snippets/pom.xml +++ b/samples/doc-snippets/pom.xml @@ -5,7 +5,7 @@ io.akka akka-javasdk-parent - 3.1.0-a7630cc-37-b1638f53-dev-SNAPSHOT + 3.1.0 com.example @@ -14,48 +14,4 @@ jar doc-snippets - - - - 2.5.1 - - - - akka-repository - Akka library repository - https://repo.akka.io/maven - - - - - com.lightbend.akka.grpc - akka-grpc-runtime_2.13 - ${akka.grpc.version} - - - - - - com.lightbend.akka.grpc - akka-grpc-maven-plugin - ${akka.grpc.version} - - - - true - - - - - - - generate - - - - - - - diff --git a/samples/doc-snippets/src/main/protobuf/com/example/example_grpc_endpoint.proto b/samples/doc-snippets/src/main/proto/com/example/example_grpc_endpoint.proto similarity index 100% rename from samples/doc-snippets/src/main/protobuf/com/example/example_grpc_endpoint.proto rename to samples/doc-snippets/src/main/proto/com/example/example_grpc_endpoint.proto