Re: Error when compile a Probuf generated java file

24 views
Skip to first unread message

DiveInto

unread,
Mar 28, 2013, 10:29:15 PM3/28/13
to simple-b...@googlegroups.com
I have add a repo at github: https://github.com/DiveInto/probuf-sbt

you can re-produce the error run sbt package-dist 

在 2013年3月29日星期五UTC+8上午10时06分06秒,DiveInto写道:
In my project, I have Java code generated by probuf.

while when I try to package my project(using twitter's sbt-package-dist )Error occurred:

[error] /path/to/my/project/src/main/java/com/mycompany/dp/my/protocol/myResponseProtocol.java:458: reference to Builder is ambiguous;
[error] it is both defined in object myResponse and imported subsequently by
[error] import ServiceStats._
[error]       public Builder newBuilderForType() { return newBuilder(); }
[error]              ^
[error] /path/to/my/project/src/main/java/com/mycompany/dp/my/protocol/myResponseProtocol.java:462: reference to Builder is ambiguous;
[error] it is both defined in object myResponse and imported subsequently by
[error] import ServiceStats._
[error]       public Builder toBuilder() { return newBuilder(this); }
[error]              ^
[error] /path/to/my/project/src/main/java/com/mycompany/dp/my/protocol/myRequestProtocol.java:321: reference to Builder is ambiguous;
[error] it is both defined in object myRequest and imported subsequently by
[error] import RawDeviceInfo._
[error]       public Builder newBuilderForType() { return newBuilder(); }
[error]              ^
[error] /path/to/my/project/src/main/java/com/mycompany/dp/my/protocol/myRequestProtocol.java:325: reference to Builder is ambiguous;
[error] it is both defined in object myRequest and imported subsequently by
[error] import RawDeviceInfo._
[error]       public Builder toBuilder() { return newBuilder(this); }
[error]              ^

myResponseProtocol.java and myRequestProtocol.java are java classes generated using Probuf, the .probuf file looks like this(quit normal):

package com.umeng.dp.my.protocol;
// FATAL: This name works as a version number
// Increase this number everytime you do a non-compatible modification!!
// The block storage writer is responsible for write the version number.
option java_outer_classname = "myResponseProtocol";
message myResponse {
    optional uint64 request_id = 1;
    optional string my = 2;
    enum StatusCode {
        NORMAL = 0;
        DB_FAIL = 1;
        INVALID = 2;
    }
    optional StatusCode status_code = 3;
    optional string error_message = 4;
    enum mySource {
        FID = 0;
        ...
    }
    optional mySource my_source = 5;
    message ServiceStats {
        optional uint32 db_latency_avg = 1;
        optional uint32 db_latency_max = 2;
        ...
        ...
    }
    optional ServiceStats service_stats = 6;


Any idea why this error happens?

Mark Harrah

unread,
Apr 3, 2013, 10:56:04 AM4/3/13
to simple-b...@googlegroups.com
On Thu, 28 Mar 2013 19:06:06 -0700 (PDT)
DiveInto <diveinto...@gmail.com> wrote:

> In my project, I have Java code generated by probuf.
>
> while when I try to package my project(using twitter's sbt-package-dist<https://github.com/twitter/sbt-package-dist>
I assume you have Scala sources defined in the same project as these generated Java sources. The way a mixed Java and Scala project is compiled is configured by the compileOrder setting:

http://www.scala-sbt.org/release/docs/Detailed-Topics/Java-Sources.html

By default, sbt assumes you might have dependencies between Scala and Java sources and therefore it needs to pass both Scala and Java sources to scalac first. scalac processes enough of the Java sources to compile the Scala sources and generate class files for the Scala sources only. Then, javac compiles the Java sources, which can succeed because the classfiles for the Scala sources are now available.

In your case, I assume the error is coming from the Scala compiler processing the Java sources incorrectly. If your Java sources have no dependencies on the Scala sources, you can set compileOrder to compile Java sources first with javac and then Scala sources only second with scalac:

compileOrder := CompilerOrder.JavaThenScala

-Mark

>
> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
> To post to this group, send email to simple-b...@googlegroups.com.
> Visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages