Skip to content

Commit

Permalink
feat: gRPC codegen config in parent pom
Browse files Browse the repository at this point in the history
  • Loading branch information
johanandren committed Jan 23, 2025
1 parent 4a244fb commit 97b6385
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 65 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 34 additions & 14 deletions akka-javasdk-maven/akka-javasdk-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>

<akka-javasdk.version>3.0.2</akka-javasdk.version>
<!-- must be carefully kept in sync with sdk and runtime version -->
<akka.grpc.version>2.5.1</akka.grpc.version>

<!-- These are dependent on runtime environment and cannot be customized by users -->
<maven.compiler.release>21</maven.compiler.release>
Expand Down Expand Up @@ -425,6 +427,38 @@
</plugins>
</build>
</profile>

<profile>
<id>generate-protobuf-endpoints</id>
<activation>
<file>
<exists>src/main/protobuf</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.lightbend.akka.grpc</groupId>
<artifactId>akka-grpc-maven-plugin</artifactId>
<version>${akka.grpc.version}</version>
<configuration>
<generatorSettings>
<!-- required to generate the instance-per-request handler -->
<generateScalaHandlerFactory>true</generateScalaHandlerFactory>
</generatorSettings>
</configuration>
<!-- Hook the generate goal into the lifecycle, automatically tied to generate-sources -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencyManagement>
Expand All @@ -433,25 +467,11 @@
<groupId>io.akka</groupId>
<artifactId>akka-javasdk</artifactId>
<version>${akka-javasdk.version}</version>
<!-- FIXME, just a temporal dependency issues fix -->
<exclusions>
<exclusion>
<groupId>com.lightbend.akka.grpc</groupId>
<artifactId>akka-grpc-runtime_2.13</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.akka</groupId>
<artifactId>akka-javasdk-testkit</artifactId>
<version>${akka-javasdk.version}</version>
<!-- FIXME, just a temporal dependency issues fix -->
<exclusions>
<exclusion>
<groupId>com.lightbend.akka.grpc</groupId>
<artifactId>akka-grpc-runtime_2.13</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.kalix</groupId>
Expand Down
27 changes: 23 additions & 4 deletions project/Common.scala
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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 {

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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = """<akka\.grpc\.version>([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 {
Expand Down
10 changes: 8 additions & 2 deletions project/SamplesCompilationProject.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
}
Expand Down
46 changes: 1 addition & 45 deletions samples/doc-snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.akka</groupId>
<artifactId>akka-javasdk-parent</artifactId>
<version>3.1.0-a7630cc-37-b1638f53-dev-SNAPSHOT</version>
<version>3.1.0</version>
</parent>

<groupId>com.example</groupId>
Expand All @@ -14,48 +14,4 @@
<packaging>jar</packaging>

<name>doc-snippets</name>

<!-- fixme move to parent, or some other opt-in solution -->
<properties>
<akka.grpc.version>2.5.1</akka.grpc.version>
</properties>
<pluginRepositories>
<pluginRepository>
<id>akka-repository</id>
<name>Akka library repository</name>
<url>https://repo.akka.io/maven</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.lightbend.akka.grpc</groupId>
<artifactId>akka-grpc-runtime_2.13</artifactId>
<version>${akka.grpc.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.lightbend.akka.grpc</groupId>
<artifactId>akka-grpc-maven-plugin</artifactId>
<version>${akka.grpc.version}</version>
<configuration>
<generatorSettings>
<!-- required to generate the instance-per-request handler -->
<generateScalaHandlerFactory>true</generateScalaHandlerFactory>
</generatorSettings>
</configuration>
<!-- Hook the generate goal into the lifecycle,
automatically tied to generate-sources -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 97b6385

Please sign in to comment.