How to reduce the build

This guide will help you clean up the build scripts, so your build only includes the dependencies, plugins, and settings you need.

This guide assumes you created a new project using the Akka Microservices template.

The project from the template uses sbt as a build tool. The build is split in two files:

  1. build.sbt

  2. project/plugins.sbt

Because the template adds all the dependencies, plugins, and settings required to build the full application used in the Microservices tutorial it is likely you can remove some bits.

Remove support for gRPC and protobuf

If you don’t need to serve or consume gRPC traffic, or use any protobuf serializer, then you can remove the Akka gRPC plugin. You must remove two parts:

  1. the Akka gRPC plugin dependency

project/plugins.sbt
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.1.0")
  1. the Akka gRPC plugin activation

build.sbt
enablePlugins(AkkaGrpcPlugin)

If you are not serving any gRPC traffic, you may also remove the dependency to the Akka HTTP artifact that adds support for HTTP/2:

build.sbt
  "com.typesafe.akka" %% "akka-http2-support" % AkkaHttpVersion,

Replace the Persistence plugin

The project produced with the Akka Microservices template assumes the application will use the Akka Persistence Cassandra plugin new tab. You can opt out from using that plugin and use the Akka Persistence JDBC new tab or other plugins instead.

  1. The first thing you must do is to remove the dependency to the Akka Persistence Cassandra plugin:

    1. remove the value declaring the dependency version

      build.sbt
      val AkkaPersistenceCassandraVersion = "1.0.5"
    2. remove the value declaring the dependency

      build.sbt
        "com.typesafe.akka" %% "akka-persistence-cassandra" % AkkaPersistenceCassandraVersion,
  1. Now add the dependency of the Akka Persistence plugin you want. Let’s use, for example, the JDBC plugin:

    1. (optional) declare the version as a value:

      build.sbt
      val AkkaPersistenceJdbcVersion = "5.0.4"
    2. add the new dependency

      build.sbt
        "com.lightbend.akka" %% "akka-persistence-jdbc" % AkkaPersistenceJdbcVersion,

Replace the Offset Store database

The project produced with the Akka Microservices template assumes the application will use a Cassandra database to store the offset tracking new tab required by the projections. You can replace the artifact to use an RDBMS:

build.sbt
  -  "com.lightbend.akka" %% "akka-projection-cassandra" % AkkaProjectionVersion,
  +  "com.lightbend.akka" %% "akka-projection-jdbc" % AkkaProjectionVersion,

Note how the artifact version doesn’t change.

Replacing the artifact is only the first step. Each of the implementations of Offset Stores for Akka Projections has slightly different APIs. Refer to the Akka Projections reference documentation new tab for more details.

Remove support for Kafka

The project produced with the Akka Microservices template projects data include the necessary dependencies to project data to a Kafka topic. If you are not projecting data into Kafka, remove the version declaration and the artifact:

build.sbt
val AlpakkaKafkaVersion = "2.0.7"
build.sbt
  "com.typesafe.akka" %% "akka-stream-kafka" % AlpakkaKafkaVersion,

Remove projections

If you are not projecting your data to a read-side you can remove all the artifacts provided by Akka Projections new tab:

  1. remove the value declaring the dependency version

    build.sbt
    val AkkaProjectionVersion = "1.2.2"
  2. remove the value declaring the dependencies (both compile and test scopes)

    build.sbt
      "com.lightbend.akka" %% "akka-projection-eventsourced" % AkkaProjectionVersion,
      "com.lightbend.akka" %% "akka-projection-cassandra" % AkkaProjectionVersion,
      "com.lightbend.akka" %% "akka-projection-jdbc" % AkkaProjectionVersion,
      "com.typesafe.akka" %% "akka-persistence-query" % AkkaVersion,
      "com.lightbend.akka" %% "akka-projection-testkit" % AkkaProjectionVersion % Test,