Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gRPC codegen config in parent pom #170

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/proto</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.")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have this check in place. 👍


}

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
3 changes: 2 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
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>
Loading