line / armeria

Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
https://armeria.dev
Apache License 2.0
4.83k stars 921 forks source link

Failed to bootstrap grpc DocService, may cause by protobuf remove some field and method #5955

Open HongYunCloud opened 1 month ago

HongYunCloud commented 1 month ago
dependencies {
    api("io.grpc:grpc-stub:1.68.0")
    api("io.grpc:grpc-protobuf:1.68.0")
    api("com.google.protobuf:protobuf-java:4.28.2")
    api("com.google.protobuf:protobuf-java-util:4.28.2")

    // armeria with version 2.5.0, but it's version is not compatible with protobuf, due to the following error:
    // Exception in thread "main" java.lang.IllegalAccessError: class org.curioswitch.common.protobuf.json.ProtobufUtil tried to access method 'boolean com.google.protobuf.Descriptors$FieldDescriptor.hasOptionalKeyword()' (org.curioswitch.common.protobuf.json.ProtobufUtil and com.google.protobuf.Descriptors$FieldDescriptor are in unnamed module of loader 'app')
    //  at org.curioswitch.common.protobuf.json.ProtobufUtil.hasOptionalKeyword(ProtobufUtil.java:306)
    api("org.curioswitch.curiostack:protobuf-jackson:2.6.0")
}
Exception in thread "main" java.util.ServiceConfigurationError: com.linecorp.armeria.server.docs.DocServicePlugin: Provider com.linecorp.armeria.internal.server.grpc.GrpcDocServicePlugin could not be instantiated
    at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586)
    at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:813)
    at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:729)
    at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403)
    at com.linecorp.armeria.internal.shaded.guava.collect.ImmutableList.copyOf(ImmutableList.java:279)
    at com.linecorp.armeria.internal.shaded.guava.collect.ImmutableList.copyOf(ImmutableList.java:240)
    at com.linecorp.armeria.server.docs.DocService.<clinit>(DocService.java:105)
    at bot.inker.asteroid.core.AsteroidArmeriaServer.server(AsteroidArmeriaServer.java:30)
    at bot.inker.asteroid.core.AsteroidArmeriaServer.start(AsteroidArmeriaServer.java:63)
    at bot.inker.asteroid.core.AsteroidBotFramework.main(AsteroidBotFramework.java:11)
Caused by: java.lang.NoSuchMethodError: 'com.google.protobuf.util.JsonFormat$Printer com.google.protobuf.util.JsonFormat$Printer.includingDefaultValueFields()'
    at com.linecorp.armeria.internal.server.grpc.GrpcDocServicePlugin.<clinit>(GrpcDocServicePlugin.java:96)
    at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
    at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1319)
    at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.ensureClassInitialized(MethodHandleAccessorFactory.java:300)
    at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newConstructorAccessor(MethodHandleAccessorFactory.java:103)
    at java.base/jdk.internal.reflect.ReflectionFactory.newConstructorAccessor(ReflectionFactory.java:200)
    at java.base/java.lang.reflect.Constructor.acquireConstructorAccessor(Constructor.java:549)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
    at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789)
    ... 8 more
minwoox commented 1 month ago

I believe that Armeria doens't support Protobuf 4.x version yet. Would you mind trying with the versions that Armeria uses? https://github.com/line/armeria/blob/main/dependencies.toml#L42 https://github.com/line/armeria/blob/main/dependencies.toml#L119