Skip to content
Merged
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
31 changes: 29 additions & 2 deletions sbt-plugin/src/main/scala/akka/grpc/sbt/AkkaGrpcPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package akka.grpc.sbt

import protocbridge.{ JvmGenerator, Target }
import sbt._
import sbt.{ GlobFilter, _ }
import Keys._
import akka.grpc.gen.scaladsl.ScalaServerCodeGenerator
import akka.grpc.gen.CodeGenerator
Expand Down Expand Up @@ -38,13 +38,40 @@ object AkkaGrpcPlugin extends AutoPlugin {
akkaGrpcCodeGenerators := GeneratorAndSettings(ScalaServerCodeGenerator, akkaGrpcCodeGeneratorSettings.value) :: Nil,
akkaGrpcModelGenerators := Seq[Target]((JvmGenerator("scala", ScalaPbCodeGenerator), akkaGrpcCodeGeneratorSettings.value) -> sourceManaged.value),

sourceDirectory in PB.recompile := sourceDirectory.value / "protobuf",
resourceDirectory in PB.recompile := sourceDirectory.value / "protobuf",

target in PB.recompile :=
crossTarget.value / "protobuf" / Defaults.nameForSrc(configuration.value.name),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IIUC, this goes hand in hand with line 41

// TODO: review managedSources
managedSourceDirectories += (target in PB.recompile).value,
unmanagedResourceDirectories += (resourceDirectory in PB.recompile).value,
watchSources in Defaults.ConfigGlobal ++= (sources in PB.recompile).value,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the key setting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correction: these three lines are key (first two for dev-mode in play/lagom) and last for regular ~task's in sbt.


// configure the proto gen automatically by adding our codegen:
PB.targets :=
akkaGrpcModelGenerators.value ++
akkaGrpcCodeGenerators.value.map(adaptAkkaGenerator(sourceManaged.value)),

// include proto files extracted from the dependencies with "protobuf" configuration by default
PB.protoSources += PB.externalIncludePath.value))
PB.protoSources += PB.externalIncludePath.value) ++
inTask(PB.recompile)(
Seq(
includeFilter := GlobFilter("*.proto"),

managedSourceDirectories := Nil,
unmanagedSourceDirectories := Seq(sourceDirectory.value),
sourceDirectories := unmanagedSourceDirectories.value ++ managedSourceDirectories.value,
unmanagedSources := { Defaults.collectFiles(sourceDirectories, includeFilter, excludeFilter).value },
managedSources := Nil,
sources := managedSources.value ++ unmanagedSources.value,

managedResourceDirectories := Nil,
unmanagedResourceDirectories := Seq(resourceDirectory.value),
resourceDirectories := unmanagedResourceDirectories.value ++ managedResourceDirectories.value,
unmanagedResources := { Defaults.collectFiles(resourceDirectories, includeFilter, excludeFilter).value },
managedResources := Nil,
resources := managedResources.value ++ unmanagedResources.value)))

def adaptAkkaGenerator(targetPath: File)(generatorAndSettings: GeneratorAndSettings): Target = {
val adapted = new ProtocBridgeSbtPluginCodeGenerator(generatorAndSettings.generator)
Expand Down