scalapb-validate-codegen not found

10 views
Skip to first unread message

Chris Toomey

unread,
Mar 23, 2021, 9:50:01 PMMar 23
to ScalaPB
Hi, I just came across https://github.com/envoyproxy/protoc-gen-validate and https://scalapb.github.io/docs/validation and am excited to try it, but getting

ResolveException: unresolved dependency: com.thesamet.scalapb#scalapb-validate-codegen_2.12;0.3.0: not found

What sbt resolver do I need to add for this?

thanks,
Chris

Nadav Samet

unread,
Mar 23, 2021, 11:17:53 PMMar 23
to Chris Toomey, ScalaPB
Hi Chris, 

Sorry for the confusion - I've recently pushed a change to the documentation site that reference versions that were not released yet. 0.3.0 will come out in the coming days. For the time being, use scalapb-validate version 0.2.2 which works with ScalaPB 0.10.11.


--
You received this message because you are subscribed to the Google Groups "ScalaPB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalapb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalapb/94c6e4ee-1a4e-46c2-bf7f-dac99c6648bfn%40googlegroups.com.


--
-Nadav

Chris Toomey

unread,
Mar 24, 2021, 1:16:17 AMMar 24
to Nadav Samet, ScalaPB
OK thanks Nadav.

You received this message because you are subscribed to a topic in the Google Groups "ScalaPB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalapb/-A5zYFVnCJg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalapb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalapb/CANZcNEr4ExgLh64pgNqNd2Z16aDdHh8CopNdMspAt0bd6yf1xw%40mail.gmail.com.

Nadav Samet

unread,
Mar 25, 2021, 12:57:51 AMMar 25
to Chris Toomey, ScalaPB
Hi Chris, scalapb-validate 0.3.0 is now available, supporting ScalaPB 0.11.0 and PGV 0.4.1.
--
-Nadav

Chris Toomey

unread,
Mar 26, 2021, 4:36:43 PMMar 26
to Nadav Samet, ScalaPB
Nadav, I've been unable to get the code generation for scalapb-validate to work. I'm using akka-grpc, and have tried with akka-grpc versions 1.1.1 (latest) and 1.0.2, and with scalapb-validate versions 0.1.4, 0.2.2, and 0.3.0. I've added this to my build.sbt to reflect the location where the generated protobuf and grpc .scala files are placed.
Compile / PB.targets ++= Seq(
scalapb.validate.gen() -> crossTarget.value / "akka-grpc" / "main"
)
Here are the errors I get with each. Would appreciate any suggestions you have for tweaking versions or settings to get this to work.
0.3.0:
[info] Generating Akka gRPC service interface for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service handler for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service power API handler for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service power API interface for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC client for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
--jvm_4_out: java.lang.NoSuchMethodError: com.google.protobuf.Descriptors$Descriptor.getRealOneofs()Ljava/util/List;
at scalapb.compiler.DescriptorImplicits$ExtendedMessageDescriptor.isSealedOneofType(DescriptorImplicits.scala:500)
at scalapb.compiler.DescriptorImplicits$ExtendedMessageDescriptor.scalaType(DescriptorImplicits.scala:510)
at scalapb.validate.compiler.MessagePrinter.validatorName(CodeGenerator.scala:64)
at scalapb.validate.compiler.MessagePrinter.<init>(CodeGenerator.scala:68)
at scalapb.validate.compiler.CodeGenerator$.$anonfun$process$2(CodeGenerator.scala:46)
0.2.2:
[info] Generating Akka gRPC service interface for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service handler for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service power API handler for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service power API interface for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC client for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
--jvm_4_out: java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/google/protobuf/compiler/PluginProtos$CodeGeneratorResponse$Feature
at protocgen.CodeGenResponse.toCodeGeneratorResponse(CodeGenResponse.scala:12)
at protocgen.CodeGenResponse.toCodeGeneratorResponse$(CodeGenResponse.scala:7)
at protocgen.CodeGenResponse$Internal$Success.toCodeGeneratorResponse(CodeGenResponse.scala:36)
at protocgen.CodeGenApp.run(CodeGenApp.scala:46)
at protocgen.CodeGenApp.run$(CodeGenApp.scala:39)
at scalapb.validate.compiler.CodeGenerator$.run(CodeGenerator.scala:20)
at protocgen.CodeGenApp.run(CodeGenApp.scala:31)
at protocgen.CodeGenApp.run$(CodeGenApp.scala:30)
at scalapb.validate.compiler.CodeGenerator$.run(CodeGenerator.scala:20)
0.1.4:
[info] Generating Akka gRPC service interface for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service handler for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service power API handler for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC service power API interface for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
[info] Generating Akka gRPC client for com.livongo.protobuf.grpc.internal_non_production.pregistry.PatientRegistry
com/livongo/protobuf/grpc/internal_non_production/pregistry/pregistry/GetWalletRequest.scala: Tried to insert into file that doesn't exist.
com/livongo/protobuf/grpc/internal_non_production/pregistry/pregistry/ListWalletsRequest.scala: Tried to insert into file that doesn't exist. ...

When I disable validation, the generated files are placed in target/scala-2.12/akka-grpc/main/com/livongo/protobuf/grpc/internal_non_production/pregistry, and crossTarget.value is target/scala-2.12. I've tried all these variants to try to get it to "find" the generated files that it says doesn't exist, and get the same errors with every one of them.

Compile / PB.targets ++= Seq(
// scalapb.validate.gen() -> crossTarget.value
// scalapb.validate.gen() -> crossTarget.value / "akka-grpc"
scalapb.validate.gen() -> crossTarget.value / "akka-grpc" / "main"
// scalapb.validate.gen() -> crossTarget.value / "akka-grpc" / "main" / "com" / "livongo" / "protobuf" / "grpc" / "internal_non_production" / "pregistry"
)
Here's the value of protocTargets, which shows the target/scala-2.12/akka-grpc/main directory:

$ inspect compile:protocTargets
[info] Setting: scala.collection.Seq[protocbridge.Target] = List(Target(SandboxedJvmGenerator(scala,com.thesamet.scalapb:compilerplugin_2.12:0.10.8(crossVersion=false),List(com.thesamet.scalapb:scalapb-runtime:0.10.8(crossVersion=true)),protocbridge.SandboxedJvmGenerator$$$Lambda$6024/1316158537@74ed9cd6),/Users/christoomey/unix/dev/grpcValidationUpgrade/target/scala-2.12/akka-grpc/main,List(flat_package)), Target(SandboxedJvmGenerator(akka-grpc-scaladsl-trait,com.lightbend.akka.grpc:akka-grpc-codegen_2.12:1.0.2(crossVersion=false),List(com.lightbend.akka.grpc:akka-grpc-runtime_2.12:1.0.2(crossVersion=false)),akka.grpc.sbt.GeneratorBridge$$$Lambda$6049/1040418078@2de8cadc),/Users/christoomey/unix/dev/grpcValidationUpgrade/target/scala-2.12/akka-grpc/main,List(flat_package, server_power_apis, use_play_actions)), Target(SandboxedJvmGenerator(akka-grpc-scaladsl-server,com.lightbend.akka.grpc:akka-grpc-codegen_2.12:1.0.2(crossVersion=false),List(com.lightbend.akka.grpc:akka-grpc-runtime_2.12:1.0.2(crossVersion=false)),akka.grpc.sbt.GeneratorBridge$$$Lambda$6049/1040418078@51c6e209),/Users/christoomey/unix/dev/grpcValidationUpgrade/target/scala-2.12/akka-grpc/main,List(flat_package, server_power_apis, use_play_actions)), Target(SandboxedJvmGenerator(akka-grpc-scaladsl-client,com.lightbend.akka.grpc:akka-grpc-codegen_2.12:1.0.2(crossVersion=false),List(io.grpc:grpc-stub:1.32.1(crossVersion=false), com.lightbend.akka.grpc:akka-grpc-runtime_2.12:1.0.2(crossVersion=false)),akka.grpc.sbt.GeneratorBridge$$$Lambda$6049/1040418078@5b031055),/Users/christoomey/unix/dev/grpcValidationUpgrade/target/scala-2.12/akka-grpc/main,List(flat_package, server_power_apis, use_play_actions)), Target(SandboxedJvmGenerator(scala,com.thesamet.scalapb:scalapb-validate-codegen_2.12:0.1.4(crossVersion=false),List(com.thesamet.scalapb:scalapb-validate-core:0.1.4(crossVersion=true)),protocbridge.SandboxedJvmGenerator$$$Lambda$6024/1316158537@43902ccf),/Users/christoomey/unix/dev/grpcValidationUpgrade/target/scala-2.12,List()))

Nadav Samet

unread,
Mar 26, 2021, 5:13:50 PMMar 26
to Chris Toomey, ScalaPB
Hi Chris, akka-grpc 1.1.1 works with ScalaPB 0.10.x, so the corresponding version of scalapb-validate would be 0.2.2

akka-grpc changes the default ScalaPB settings by adding the "flatPackage" as a generator option, which affects the location of the generated files. The way to solve it would be to pass FlatPackage as a parameter to scalapb.validate.gen:

Compile / PB.targets ++= Seq(
  scalapb.validate.gen(scalapb.GeneratorOption.FlatPackage) -> (Compile / akkaGrpcCodeGeneratorSettings / target).value
)

Please also take a look at this sbt-test at akka-grpc which has a working sbt build with akka-grpc and scalapb-validate: https://github.com/akka/akka-grpc/tree/0288da3406cfb61368cc19d4f8f02e139301a79a/sbt-plugin/src/sbt-test/gen-scala-server/10-scalapb-validate







--
-Nadav
Message has been deleted

Chris Toomey

unread,
Apr 1, 2021, 10:41:10 AMApr 1
to ScalaPB
Thanks Nadav, that fixed my akka-grpc compilation issues.

The next step for me was getting it to work with the play-grpc-generators plugin which we use to add Play-specific grpc code. When I added that to the mix, I started getting the compilation error

java.lang.NoSuchMethodError: com.google.protobuf.Descriptors$FileDescriptor.internalBuildGeneratedFileFrom([Ljava/lang/String;[Lcom/google/protobuf/Descriptors$FileDescriptor;)Lcom/google/protobuf/Descriptors$FileDescriptor;

This one took me quite a while to figure out but I ultimately found it was due to sbt itself bringing in a dependency on protobuf-java:3.7.0, while play-grpc-generators was built against a newer protobuf-java which added the above method. After digging around the sbt repo I discovered that newer sbt versions (I was using 1.2.1) dropped that dependency on protobuf-java, so once I upgraded (to 1.4.7 in my case) the problem was solved.

Mainly I'm posting this as an FYI in case others come across this in the future.

Thanks again for your help.

Chris
Reply all
Reply to author
Forward
0 new messages