rules_proto_grpc icon indicating copy to clipboard operation
rules_proto_grpc copied to clipboard

Java: Imported enums from local dependency proto files cannot be used as repeated members

Open loudmouth opened this issue 10 months ago • 4 comments

Issue Description

When importing an enum from another protobuf file in the same repo (local dependency) that enum can be used as a member field, but cannot be used as a repeated member field in java_proto_library and java_grpc_library. This issue is reproducible with both versions 5.0.0 and 5.0.1 of rules_proto_grpc_java.

I've pushed a small repo reproducing the issue. This line of code is the source. Changing the usage of the enum to a non-repeated field or commenting it out, the build works, but as a repeated field it fails.

Our project currently is on version 4.4.0 and we are able to build java_proto_library and java_grpc_library with that version when we import enums from dependency protobuf files and use them as repeated members, the targets build succesfully.

Log Output

bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:127: error: cannot find symbol
  private static final com.google.protobuf.Internal.IntListAdapter.IntConverter<
                                                   ^
  symbol:   class IntListAdapter
  location: class Internal
bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:129: error: cannot find symbol
          new com.google.protobuf.Internal.IntListAdapter.IntConverter<
                                          ^
  symbol:   class IntListAdapter
  location: class Internal
bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:142: error: cannot find symbol
    return new com.google.protobuf.Internal.IntListAdapter<
                                           ^
  symbol:   class IntListAdapter
  location: class Internal
bazel-out/darwin_x86_64-fastbuild/bin/protobuf/_javac/transactions_java/libtransactions_java_tmp/com/justtechnologies/proto/type/Transaction.java:847: error: cannot find symbol
      return new com.google.protobuf.Internal.IntListAdapter<
                                             ^
  symbol:   class IntListAdapter
  location: class Internal

rules_proto_grpc Version

5.0.0

Bazel Version

7.4.1

OS

MacOS Sonoma 14.6.1 (23G93)

Link to Demo Repo

https://github.com/justtechnologies/java-grpc-enum

MODULE.bazel or WORKSPACE Content

## MODULE.bazel
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "protobuf", version = "29.2", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "rules_proto_grpc_go", version = "5.0.1")
bazel_dep(name = "rules_proto_grpc_java", version = "5.0.0")
bazel_dep(name = "rules_java", version = "8.6.2")
bazel_dep(name = "rules_jvm_external", version = "6.6")
bazel_dep(name = "contrib_rules_jvm", version = "0.27.0")

BUILD Content

load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_proto_grpc_java//:defs.bzl", "java_grpc_library", "java_proto_library")

package(default_visibility = ["//visibility:public"])

## Proto Libraries
proto_library(
    name = "commons_proto",
    srcs = ["commons.proto"],
)

proto_library(
    name = "transactions_proto",
    srcs = ["transactions.proto"],
    deps = [
        ":commons_proto",
        "@com_google_protobuf//:duration_proto",
        "@com_google_protobuf//:empty_proto",
        "@com_google_protobuf//:timestamp_proto",
    ],
)

# # Java
java_proto_library(
    name = "commons_java",
    protos = [":commons_proto"],
)

java_grpc_library(
    name = "transactions_java",
    protos = [
        ":commons_proto",
        ":transactions_proto",
    ],
)

Proto Content

commons.proto:


syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.justtechnologies.proto.type";
option java_outer_classname = "CommonsProto";

option go_package = "github.com/justtechnologies/java-gprc-enum/protobuf/commons";

package commons;

// Transaction side.
enum Side {
    SIDE_UNKNOWN = 0;
    SIDE_BUY = 1;
    SIDE_SELL = 2;
}


transactions.proto
```protobuf
syntax = "proto3";

option java_multiple_files = true;
option java_package = "com.justtechnologies.proto.type";
option java_outer_classname = "TransactionsProto";

option go_package = "github.com/justtechnologies/java-gprc-enum/protobuf/transactions";

package transactions;

import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/duration.proto";
import "protobuf/commons.proto";

service Transactions {
    rpc ListTransactions(google.protobuf.Empty) returns (ListTransactionResponse) {}
}

message ListTransactionResponse {
    repeated Transaction transactions = 1;
}

message Transaction {
    string id = 1;
    google.protobuf.Timestamp timestamp = 2;
    double amount = 3;
    repeated commons.Side side = 4;
}


### Any Other Content

_No response_

loudmouth avatar Dec 19 '24 19:12 loudmouth