Very simple grpc/proto endpoint implementation causing java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReferenceImpl

Very simple grpc/proto endpoint implementation causing java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReferenceImpl

我发现的最接近的问题是 this one,基本上它说:“......你在 运行time 类路径上使用的 kotlin-stdlib 版本不低于编译时的版本类路径...“

据我所知,我对 kotlin 版本的看法是正确的。

我的整个项目很小,可以从github

下载

build.gradle

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.4.10"
    id("org.jetbrains.kotlin.kapt") version "1.4.10"
    id("org.jetbrains.kotlin.plugin.allopen") version "1.4.10"
    id("com.github.johnrengelman.shadow") version "6.1.0"
    id("io.micronaut.application") version "1.2.0"
    id("com.google.protobuf") version "0.8.13"
}

version = "0.1"
group = "com.tolearn"

repositories {
    mavenCentral()
    jcenter()
}

micronaut {
    testRuntime("junit5")
    processing {
        incremental(true)
        annotations("com.tolearn.*")
    }
}

dependencies {

    implementation("io.grpc:protoc-gen-grpc-kotlin:1.0.0:jdk7@jar")
    api("io.grpc:grpc-kotlin-stub:1.0.0")

    implementation("io.micronaut:micronaut-validation")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
    implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
    implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
    implementation("io.micronaut:micronaut-runtime")
    implementation("io.micronaut.grpc:micronaut-grpc-runtime")
    implementation("javax.annotation:javax.annotation-api")
    implementation("io.micronaut:micronaut-http-client")
    runtimeOnly("ch.qos.logback:logback-classic")
    runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
}


application {
    mainClass.set("com.tolearn.ApplicationKt")
}

java {
    sourceCompatibility = JavaVersion.toVersion("11")
}

tasks {
    compileKotlin {
        kotlinOptions {
            jvmTarget = "11"
        }
    }
    compileTestKotlin {
        kotlinOptions {
            jvmTarget = "11"
        }
    }


}
sourceSets {
    main {
        java {
            srcDirs("build/generated/source/proto/main/grpc")
            srcDirs("build/generated/source/proto/main/java")
            srcDirs 'build/generated/source/proto/main/grpckt'
        }
    }
}

protobuf {
    protoc { artifact = "com.google.protobuf:protoc:3.14.0" }
    plugins {
        grpc { artifact = "io.grpc:protoc-gen-grpc-java:1.34.1" }
        grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:1.0.0:jdk7@jar" }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {}
            grpckt {}
        }
    }
}

gradle.properties

micronautVersion=2.2.2
kotlinVersion=1.4.10

我尝试在 IntelliJ 中调试应用程序时的完整日志

C:\JDKs\jdk-11.0.6\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\lib\idea_rt.jar=57835:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\bin" -Dfile.encoding=UTF-8 -classpath C:\_d\toLearn\demo-money\build\classes\java\main;C:\_d\toLearn\demo-money\build\classes\kotlin\main;C:\_d\toLearn\demo-money\build\tmp\kapt3\classes\main;C:\_d\toLearn\demo-money\build\resources\main;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-kotlin-stub.0.0\a9b64135291f02726f437bf82822142dea3d963d\grpc-kotlin-stub-1.0.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\protoc-gen-grpc-kotlin.0.0\d6c8cbe29c60b202165593be5244ce43d37378ac\protoc-gen-grpc-kotlin-1.0.0-jdk7.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-validation.2.2c9978ae69745ab3c5afd37d3c2e6c7f5a59190b\micronaut-validation-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8.4.108caa30623f73223194a8b657abd2baec4880ea\kotlin-stdlib-jdk8-1.4.10.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect.4.10\e2b3c6695eee6085e606d96d685396dce23a3a06\kotlin-reflect-1.4.10.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut.kotlin\micronaut-kotlin-runtime.2.0\b8b24a7e5ea4d68afd6edc283f2b1f944bbf2cc7\micronaut-kotlin-runtime-2.2.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-http-client.2.20a9b3ee54d66b838675e62df3c9bbdd8f1028b\micronaut-http-client-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut.grpc\micronaut-grpc-runtime.2.0ed2e5c0f592d2f92eab105f60293f0c1cab6e92\micronaut-grpc-runtime-2.2.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-runtime.2.2\ffee1b2088cd3bd699646940dc37ccc537d6f77\micronaut-runtime-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-inject.2.2\dbbd8cf931e3714ef0e9ce635a1023a383785c25\micronaut-inject-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api.3.24c04d3cfef185a8008e7bf34331b79730a9d43\javax.annotation-api-1.3.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-protobuf.33.199a8c87e4264be11749b0e3c82526fb7481daf\grpc-protobuf-1.33.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-stub.33.1\cf2c3b997646a3f065efbaa72528dc7c67e80d77\grpc-stub-1.33.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-http.2.2e8dbd9635f2ae40acf95dfeecf424cc46d759a0\micronaut-http-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api.7.26100a62c2e6f04b53977b9f541044d7d722693d\slf4j-api-1.7.26.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\javax.validation\validation-api.0.1.Final\cb855558e6271b1b32e716d24cb85c7f583ce09e\validation-api-2.0.1.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7.4.10e46450b0bb3dbf43898d2f461be4a942784780\kotlin-stdlib-jdk7-1.4.10.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib.4.10\ea29e063d2bbe695be13e9d044dcfb0c7add398e\kotlin-stdlib-1.4.10.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-http-client-core.2.2\b939e521a859d2f691f352d2d274693d2e979039\micronaut-http-client-core-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-http-netty.2.2\d95de1cfb8f14ebe7c025ed1d994734bdc97aa76\micronaut-http-netty-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-websocket.2.2b9727c73e352f3c2b8ad86f74f172de465c5035\micronaut-websocket-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-handler-proxy.1.56.Finalacd2ead521786303faf2f85308b98ba174c53b6\netty-handler-proxy-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut.grpc\micronaut-grpc-client-runtime.2.0ebc47606ca77e186a3e182ac5eccd0cfce193e\micronaut-grpc-client-runtime-2.2.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut.grpc\micronaut-grpc-server-runtime.2.0\f4e9472b6124f5e7db1ce229c7a1059db6589b84\micronaut-grpc-server-runtime-2.2.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-aop.2.289d1a032d2d6599c132e3f1daab239724e691d\micronaut-aop-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava.2.10e9edc67e0abaa03713eeb9ca2cb0e30c859de4\rxjava-2.2.10.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jdk8.11.2\d4c1933a8d62db65c3d5a5cd809511e021a189c0\jackson-datatype-jdk8-2.11.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310.11.2\e6235e5eb3cf3edd2a95cd0dc96bc48aeb309e8a\jackson-datatype-jsr310-2.11.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-core.2.2\c85844828723dcd0ccbf9fa70cb406d6c49d083b\micronaut-core-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml.26\a78a8747147d2c5807683e76ec2b633e95c14fe9\snakeyaml-1.26.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\javax.inject\javax.inject75da39a7040257bd51d21a231b76c915872d38\javax.inject-1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-protobuf-lite.33.172b32eca6661ac99f0d0d1f6bc78836a0aaa98\grpc-protobuf-lite-1.33.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-api.33.10c50b7376a5083392a35cace95fbe121fefbc3\grpc-api-1.33.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.code.findbugs\jsr305.0.2ea2e8b0c338a877313bd4672d3fe056ea78f0d\jsr305-3.0.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.protobuf\protobuf-java.14.0\bb6430f70647fc349fffd1690ddb889dc3ea6699\protobuf-java-3.14.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.api.grpc\proto-google-common-protos.17.0471bf2045151c17da555889b5550fcfd5224a8\proto-google-common-protos-1.17.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.guava\guava.0-android\a51b7d9cbfcce79a88c961907c1767c6de201f31\guava-29.0-android.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.errorprone\error_prone_annotations.3.4\dac170e4594de319655ffb62f41cbd6dbb5e601e\error_prone_annotations-2.3.4.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common.4.1029be3465805c99db1142ad75e6c6ddeac0b04c\kotlin-stdlib-common-1.4.10.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations.09f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut\micronaut-buffer-netty.2.2\fec1f3c421efbffaefa261e85d0f967b5157cd52\micronaut-buffer-netty-2.2.2.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-codec-http2.1.56.Final4a9dc7d71e1d8df8cddf588f52f3a353ed30c6\netty-codec-http2-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-codec-http.1.56.Final\b67fa83d89476f66de30fa0808cf2fd019a43a06\netty-codec-http-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-handler.1.56.Finala3ccbc2c9d0b462643a1904ae6cdb84169546\netty-handler-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-codec-socks.1.56.Finalbda6496c20c477d475e63934571eebdd07560e1\netty-codec-socks-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-codec.1.56.Finald828cca651f2a37de5735f0d79cbe77228c9d21\netty-codec-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-transport.1.56.Final09fc38a761463f2f43032918e9d455a622f6be\netty-transport-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-buffer.1.56.Final466b8de0e325a906c53bbaa9585091ef22001d\netty-buffer-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-common.1.56.Finale4888cfc66b7ec5a9fb291d9593511481274089\netty-common-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.micronaut.grpc\micronaut-grpc-annotation.2.0\cecd044579bcbb555bea1f74becc172df8131fd1\micronaut-grpc-annotation-2.2.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.reactivestreams\reactive-streams.0.3\d9fb7a7926ffa635b3dcaa5049fb2bfa25b3e7d0\reactive-streams-1.0.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.github.spotbugs\spotbugs-annotations.0.35cc5d84d32b31beeaf8597181f0fc4eac98e16\spotbugs-annotations-4.0.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-context.33.1d312ce1acad9869f118f01cef70a1d5ae7657a8\grpc-context-1.33.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.guava\failureaccess.0.1dcf1de382a0bf95a3d8b0849546c88bac1292c9\failureaccess-1.0.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.guava\listenablefuture99.0-empty-to-avoid-conflict-with-guava\b421526c5f297295adef1c886e5246c39d4ac629\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.checkerframework\checker-compat-qual.5.55dc33e3019c9f019e15f01aa111de9d6b2b79c\checker-compat-qual-2.5.5.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.j2objc\j2objc-annotations.3\ba035118bc8bac37d7eff77700720999acd9986d\j2objc-annotations-1.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.netty\netty-resolver.1.56.Final8076140d58591265533418529e28c7ebbf8422\netty-resolver-4.1.56.Final.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-kotlin.11.3\ad8d29545c5ab0cdd6d49ee38f7ece8d9f772815\jackson-module-kotlin-2.11.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic.2.3c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-core.3.3bac48cf5828e9b006f3b1ef6e37d2a70c2e7321\kotlinx-coroutines-core-1.3.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.typesafe\config.4.1058a07624a87f90d129af7cd9c68bee94535a9\config-1.4.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind.11.3f7b27416934dc929bb6c2d2c5fe521829e6a4ec\jackson-databind-2.11.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations.11.3d4e9c777e7a8805c4a000a8629d3009c779c9b\jackson-annotations-2.11.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core.2.34344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\org.codehaus.mojo\animal-sniffer-annotations.18\f7aa683ea79dc6681ee9fb95756c999acbb62f5d\animal-sniffer-annotations-1.18.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-netty.33.1\db8c0e98533e5b57264dac2ef827661724f2575f\grpc-netty-1.33.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core.11.3\c2351800432bdbdd8284c3f5a7f0782a352aa84a\jackson-core-2.11.3.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.grpc\grpc-core.33.1343c9703cd8a44cc2978b117b0a964d470e263\grpc-core-1.33.1.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\io.perfmark\perfmark-api[=12=].19.0bfc352777fa6e27ad1e11d11ea55651ba93236b\perfmark-api-0.19.0.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.code.gson\gson.8.680733b7df8542621dc12e21e87557e8c99b8cb\gson-2.8.6.jar;C:\Users\Cast\.gradle\caches\modules-2\files-2.1\com.google.android\annotations.1.1.4\a1678ba907bf92691d879fef34e1a187038f9259\annotations-4.1.1.4.jar com.tolearn.ApplicationKt
13:56:09.732 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Error instantiating bean of type  [io.micronaut.grpc.server.GrpcEmbeddedServer]

Message: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
Path Taken: new GrpcEmbeddedServer(ApplicationContext applicationContext,ApplicationConfiguration applicationConfiguration,GrpcServerConfiguration grpcServerConfiguration,[ServerBuilder serverBuilder],ApplicationEventPublisher eventPublisher,ComputeInstanceMetadataResolver computeInstanceMetadataResolver,List metadataContributors)
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [io.micronaut.grpc.server.GrpcEmbeddedServer]

Message: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
Path Taken: new GrpcEmbeddedServer(ApplicationContext applicationContext,ApplicationConfiguration applicationConfiguration,GrpcServerConfiguration grpcServerConfiguration,[ServerBuilder serverBuilder],ApplicationEventPublisher eventPublisher,ComputeInstanceMetadataResolver computeInstanceMetadataResolver,List metadataContributors)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1925)
    at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2679)
    at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2665)
    at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2337)
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2311)
    at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1245)
    at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
    at io.micronaut.grpc.server.$GrpcEmbeddedServerDefinition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898)
    at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2679)
    at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2665)
    at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2337)
    at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2311)
    at io.micronaut.context.DefaultBeanContext.findBean(DefaultBeanContext.java:1266)
    at io.micronaut.context.DefaultBeanContext.findBean(DefaultBeanContext.java:744)
    at io.micronaut.context.BeanLocator.findBean(BeanLocator.java:149)
    at io.micronaut.runtime.Micronaut.start(Micronaut.java:66)
    at com.tolearn.ApplicationKt.main(Application.kt:8)
Caused by: java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
    at com.tolearn.endpoint.DemoMoneyServiceGrpcKt$DemoMoneyServiceCoroutineImplBase$bindService.<init>(DemoMoneyGrpcKt.kt)
    at com.tolearn.endpoint.DemoMoneyServiceGrpcKt$DemoMoneyServiceCoroutineImplBase.bindService(DemoMoneyGrpcKt.kt:90)
    at io.grpc.internal.AbstractServerImplBuilder.addService(AbstractServerImplBuilder.java:120)
    at io.grpc.internal.AbstractServerImplBuilder.addService(AbstractServerImplBuilder.java:56)
    at io.micronaut.grpc.server.GrpcServerBuilder.serverBuilder(GrpcServerBuilder.java:58)
    at io.micronaut.grpc.server.$GrpcServerBuilder$ServerBuilder0Definition.build(Unknown Source)
    at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898)
    ... 17 common frames omitted

Process finished with exit code 1

当我尝试从命令行 gradle 运行 时记录

C:\_d\toLearn\demo-money>gradle run

> Task :run FAILED
14:43:44.395 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Error instantiating bean of type  [io.micronaut.grpc.server.GrpcEmbeddedServer]

Message: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
Path Taken: new GrpcEmbeddedServer(ApplicationContext applicationContext,ApplicationConfiguration applicationConfiguration,GrpcServerConfiguration grpcServerConfiguration,[ServerBuilder serverBuilder],ApplicationEventPublisher eventPublisher,ComputeInstanceMetadataResolver computeInstanceMetadataResolver,List metadataContributors)
io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type  [io.micronaut.grpc.server.GrpcEmbeddedServer]

Message: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
Path Taken: new GrpcEmbeddedServer(ApplicationContext applicationContext,ApplicationConfiguration applicationConfiguration,GrpcServerConfiguration grpcServerConfiguration,[ServerBuilder serverBuilder],ApplicationEventPublisher eventPublisher,ComputeInstanceMetadataResolver computeInstanceMetadataResolver,List metadataContributors)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1925)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2679)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2665)
        at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2337)
        at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2311)
        at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1245)
        at io.micronaut.context.AbstractBeanDefinition.getBeanForConstructorArgument(AbstractBeanDefinition.java:1013)
        at io.micronaut.grpc.server.$GrpcEmbeddedServerDefinition.build(Unknown Source)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingletonInternal(DefaultBeanContext.java:2679)
        at io.micronaut.context.DefaultBeanContext.createAndRegisterSingleton(DefaultBeanContext.java:2665)
        at io.micronaut.context.DefaultBeanContext.getBeanForDefinition(DefaultBeanContext.java:2337)
        at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2311)
        at io.micronaut.context.DefaultBeanContext.findBean(DefaultBeanContext.java:1266)
        at io.micronaut.context.DefaultBeanContext.findBean(DefaultBeanContext.java:744)
        at io.micronaut.context.BeanLocator.findBean(BeanLocator.java:149)
        at io.micronaut.runtime.Micronaut.start(Micronaut.java:66)
        at com.tolearn.ApplicationKt.main(Application.kt:8)
Caused by: java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
        at com.tolearn.endpoint.DemoMoneyServiceGrpcKt$DemoMoneyServiceCoroutineImplBase$bindService.<init>(DemoMoneyGrpcKt.kt)
        at com.tolearn.endpoint.DemoMoneyServiceGrpcKt$DemoMoneyServiceCoroutineImplBase.bindService(DemoMoneyGrpcKt.kt:90)
        at io.grpc.internal.AbstractServerImplBuilder.addService(AbstractServerImplBuilder.java:120)
        at io.grpc.internal.AbstractServerImplBuilder.addService(AbstractServerImplBuilder.java:56)
        at io.micronaut.grpc.server.GrpcServerBuilder.serverBuilder(GrpcServerBuilder.java:58)
        at io.micronaut.grpc.server.$GrpcServerBuilder$ServerBuilder0Definition.build(Unknown Source)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:1898)
        ... 17 common frames omitted

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\JDKs\jdk-11.0.6\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
9 actionable tasks: 1 executed, 8 up-to-date

C:\_d\toLearn\demo-money> 

IntelliJ

我猜这是版本冲突的问题,但我无法想象尝试什么。

所以我的直接问题是,我可以尝试什么来解决这个问题?可能的解决方案可能与我使用的是 kotlin-stdlib-jdk8:1.4.10 有关。如果是这样,我可以尝试什么或者降级?

有趣的是,我可以成功构建应用程序,但仅当我尝试执行时才收到上述错误

当 运行 构建 Gradle 时(感谢您提供示例项目!),有一个警告应该让您走上正确的轨道:

> Task :kaptGenerateStubsKotlin
w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
w: /home/chriki/.gradle/caches/modules-2/files-2.1/io.grpc/protoc-gen-grpc-kotlin/1.0.0/d6c8cbe29c60b202165593be5244ce43d37378ac/protoc-gen-grpc-kotlin-1.0.0-jdk7.jar: Library has Kotlin runtime bundled into it

因此,解决方案是从 implementation 配置中删除 protoc-gen-grpc-kotlin 依赖项。换句话说,从 dependencies 块中删除以下行:

    implementation("io.grpc:protoc-gen-grpc-kotlin:1.0.0:jdk7@jar")

这里不需要依赖,它指向一个只在Protobuf编译时需要的插件工件。因此,在 protobuf.plugins 下配置(已经是这种情况)应该就足够了。