thesamet / sbt-protoc

SBT plugin for generating code from Protocol Buffer using protoc
Apache License 2.0
168 stars 51 forks source link

"has" method not generated for oneofs when not using external "protoc" #345

Closed rabejens closed 1 year ago

rabejens commented 1 year ago

I have this:

message Foo {
    oneof foo {
        int32 a = 1;
        int32 b = 2;
    }
}

This is how I configured the generation:

Compile / PB.targets := Seq(
  PB.gens.java(protobufVersion) -> (Compile / sourceManaged).value,
  scalapb.gen(javaConversions = true) -> (Compile / sourceManaged).value
  )

When I do:

val x = Foo(A(42))
toJavaProto(x).getDescriptorForType // < boom!

it says:

Generated message class "foo.Foo$Foo" missing method "hasA".

When I am using an explicit protoc I installed locally, it works.

How can I instruct the builtin protoc to generate the presence methods?

rabejens commented 1 year ago

The answer was: The plugin uses an old protoc.

I added this:

ThisBuild / protocVersion := "3.24.1"

which works.