Why does the scala package name differ from the Java package name?

117 views
Skip to first unread message

Aditya Prasad

unread,
Aug 2, 2016, 4:25:21 PM8/2/16
to ScalaPB
I've got three proto files that I want to be compiled into three different packages (foo.bar, foo.baz, foo.qux). Normally I'd do this using the package specifier with those values in the respective files.

For some reason ScalaPB appends the file name (minus .proto) to the package. So while my go, java, etc. clients see

foo.bar
foo.baz
foo.qux

as the package names, my Scala code has to use

foo.bar.bar
foo.baz.baz
foo.qux.qux

I know I can work around this by using "package options," but I'd rather not. Why does ScalaPB do this instead of sharing the Java package name?

Thanks,
A


Aditya Prasad

unread,
Aug 2, 2016, 5:15:25 PM8/2/16
to ScalaPB
Ah, I just found this:

PB.flatPackage in PB.protobufConfig := true

But for some reason it doesn't work with protobuf.Any:

[error] /Users/me/work/my-project/target/src_managed/main/compiled_protobuf/my-project/v1/events/EventsProto.scala:37: value descriptor is not a member of object com.google.protobuf.AnyProto
[error]   com.google.protobuf.AnyProto.descriptor,
[error]                                ^
[error] one error found

Not sure why it would break.

Nadav Samet

unread,
Aug 2, 2016, 6:22:00 PM8/2/16
to Aditya Prasad, ScalaPB
Hi Aditya,

I summarized the cause and a possible workaround in this issue: https://github.com/trueaccord/ScalaPB/issues/155

We are adding the base file name to the generated package name as a way to avoid collisions with generated Java protocol buffers. The java code gen will take foo.proto and create a Foo static class. For Scala, if we just use the java_package, it means that Foo is not allowed as a message name or enum, and it happens to be quite a common situation.


--
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 post to this group, send email to sca...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalapb/148320b6-3b11-4863-a3d6-a0edca633616%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-Nadav

Aditya Prasad

unread,
Aug 2, 2016, 6:29:07 PM8/2/16
to ScalaPB, akpr...@gmail.com
Ah, thanks!

Nadav Samet

unread,
Aug 3, 2016, 2:05:35 AM8/3/16
to Aditya Prasad, ScalaPB
Actually, this issue has been fixed a few weeks ago and should be available in the recently released v0.5.38 (but also in 0.5.34).


For more options, visit https://groups.google.com/d/optout.



--
-Nadav
Reply all
Reply to author
Forward
0 new messages