4

I'm trying to generated java classes from protobuf.

Below is my protobuf -

syntax = "proto2";

package part2;

option java_package = "part2";

message OnlineStoreUser {
   required int32 userid = 1;
   required string username = 2;
   optional string useremail = 3;
}

I run the command main/exec/protoc --java_out=main/java main/proto/datamodel.proto

The protoc is downloaded from link https://github.com/protocolbuffers/protobuf/releases/tag/v3.7.1 where osx-x86_64.zip. I tried version 3.8.0 and 3.9.1 as well.

First error is https://gist.github.com/rajcspsg/07c1ddb889410397ba6fc6f26ab2b158#file-gistfile1-txt-L78. The argument to this function UnusedPrivateParameter type is not found.

Second error is https://gist.github.com/rajcspsg/07c1ddb889410397ba6fc6f26ab2b158#file-gistfile1-txt-L890. The is no 2 arg overloaded version of internalBuildGeneratedFileFrom.

What is wrong with my proto file. How can I fix this issue?

0

2 Answers 2

3

Make sure the dependency that you're using in your code is the same as the one that you used as protobuf compiler, for example, here I'm using gradle:

compile group: 'com.google.protobuf', name: 'protobuf-java', version: '3.11.1'

And the for my compiler version is:

✗ protoc --version                                                
libprotoc 3.11.1

Here's my test event:

syntax = "proto2";

option java_package = "com.github.irvifa.protobuf.schema";

message TestEvent {
    optional string event_name = 1 [default = "test.event"];

    optional string name = 2;
    optional string email = 3;
}

And this works.

Sign up to request clarification or add additional context in comments.

2 Comments

This is the solution, just make sure you are using the same version of probuf when you generate the class and in your maven/gradle project dependencies
Can you please mark this as the answer then? Thanks :)
2

The errors you mention only happen for me with version 3.9.1. Version 3.7.1 generates a file that doesn't use the UnusedPrivateParameter or the version of internalBuildGeneratedFileFrom with 2 parameters. It rather uses the version with 3 parameters, which does not cause any errors.

Please check that you are using the correct protoc version:

$ main/exec/protoc --version
libprotoc 3.7.1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.