Stackdriver Monitoring:具有数据流依赖性时出现 NoSuchMethodError
Stackdriver Monitoring: NoSuchMethodError when having a Dataflow dependency
当我依赖 Google Dataflow 客户端时,我无法使用 Stackdriver Monitoring 客户端从 java 应用程序构建简单指标。
我得到异常:
Exception in thread "main" java.lang.NoSuchMethodError: io.grpc.okhttp.OkHttpChannelProvider.isAndroid()Z
at io.grpc.okhttp.OkHttpChannelProvider.priority(OkHttpChannelProvider.java:51)
at io.grpc.ManagedChannelProvider.getPriority(ManagedChannelProvider.java:49)
at io.grpc.ManagedChannelProvider.getPriority(ManagedChannelProvider.java:41)
at io.grpc.ServiceProviders.compare(ServiceProviders.java:78)
at java.util.Collections$ReverseComparator2.compare(Collections.java:5178)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1462)
at java.util.Collections.sort(Collections.java:175)
at io.grpc.ServiceProviders.loadAll(ServiceProviders.java:75)
at io.grpc.ServiceProviders.load(ServiceProviders.java:42)
at io.grpc.ManagedChannelProvider.<clinit>(ManagedChannelProvider.java:37)
at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:36)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:185)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:157)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:149)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:151)
at com.google.cloud.monitoring.v3.stub.GrpcMetricServiceStub.create(GrpcMetricServiceStub.java:173)
at com.google.cloud.monitoring.v3.stub.MetricServiceStubSettings.createStub(MetricServiceStubSettings.java:184)
at com.google.cloud.monitoring.v3.MetricServiceClient.<init>(MetricServiceClient.java:158)
at com.google.cloud.monitoring.v3.MetricServiceClient.create(MetricServiceClient.java:139)
at com.google.cloud.monitoring.v3.MetricServiceClient.create(MetricServiceClient.java:130)
at SimpleMetric.main(SimpleMetric.java:7)
关于创建方法:
import com.google.cloud.monitoring.v3.MetricServiceClient;
import java.io.IOException;
public class SimpleMetric {
public static void main(String... args) throws IOException {
MetricServiceClient metricServiceClient = MetricServiceClient.create();
}
}
仅当我添加:
compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:2.5.0'
在我的 gradle 文件中作为依赖项。
plugins {
id 'java'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.cloud:google-cloud-monitoring:1.48.0'
// exception with the dependency below
compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:2.5.0'
}
我向 Google 报告了 the issue。与此同时,是否有解决方法?
isAndroid
是在 io.grpc.ManagedChannelProvider taken out of grpc-core in version 1.11 中定义的。该错误意味着您正在使用 1.11 之前的 grpc-okhttp 和 1.11 或更高版本的 grpc-core。
google-cloud-monitoring 1.48.0 间接依赖grpc-core 1.13:
com.google.cloud:google-cloud-monitoring:jar:1.48.0:compile
+- com.google.cloud:google-cloud-core:jar:1.48.0:compile
+- com.google.cloud:google-cloud-core-grpc:jar:1.48.0:compile
| +- io.grpc:grpc-protobuf:jar:1.13.1:compile
| | \- io.grpc:grpc-protobuf-lite:jar:1.13.1:compile
| +- io.grpc:grpc-context:jar:1.13.1:compile
+- com.google.api.grpc:proto-google-cloud-monitoring-v3:jar:1.30.0:compile
+- io.grpc:grpc-netty-shaded:jar:1.13.1:compile
| \- io.grpc:grpc-core:jar:1.13.1:compile (version selected from constraint [1.13.1,1.13.1])
| +- com.google.errorprone:error_prone_annotations:jar:2.1.2:compile
| +- io.opencensus:opencensus-api:jar:0.12.3:compile
| \- io.opencensus:opencensus-contrib-grpc-metrics:jar:0.12.3:compile
+- io.grpc:grpc-stub:jar:1.13.1:compile
\- io.grpc:grpc-auth:jar:1.13.1:compile
google-cloud-dataflow-java-sdk-all 2.5.0间接依赖grpc-core 1.2和grpc-okhttp 1.2:
com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:jar:2.5.0:compile
+- org.apache.beam:beam-sdks-java-io-google-cloud-platform:jar:2.5.0:compile
| +- io.grpc:grpc-core:jar:1.2.0:compile
| | +- com.google.errorprone:error_prone_annotations:jar:2.0.11:compile
| | +- io.grpc:grpc-context:jar:1.2.0:compile
| | \- com.google.instrumentation:instrumentation-api:jar:0.3.0:compile
| +- com.google.api:gax-grpc:jar:0.20.0:compile
| | +- io.grpc:grpc-protobuf:jar:1.2.0:compile
| | +- com.google.api:api-common:jar:1.1.0:compile
| | +- com.google.auto.value:auto-value:jar:1.2:compile
| | +- com.google.api:gax:jar:1.3.1:compile
| | \- org.threeten:threetenbp:jar:1.3.3:compile
| +- io.grpc:grpc-auth:jar:1.2.0:compile
| +- io.grpc:grpc-netty:jar:1.2.0:compile
| +- io.grpc:grpc-stub:jar:1.2.0:compile
| +- io.grpc:grpc-all:jar:1.2.0:compile
| | +- io.grpc:grpc-okhttp:jar:1.2.0:compile
| | | +- com.squareup.okhttp:okhttp:jar:2.5.0:compile
| | | \- com.squareup.okio:okio:jar:1.6.0:compile
所以基本上数据流已经过时并导致冲突。不再支持数据流 SDK,因为它现在是 Apache Beam。考虑 migrating 解决问题。
当我依赖 Google Dataflow 客户端时,我无法使用 Stackdriver Monitoring 客户端从 java 应用程序构建简单指标。
我得到异常:
Exception in thread "main" java.lang.NoSuchMethodError: io.grpc.okhttp.OkHttpChannelProvider.isAndroid()Z
at io.grpc.okhttp.OkHttpChannelProvider.priority(OkHttpChannelProvider.java:51)
at io.grpc.ManagedChannelProvider.getPriority(ManagedChannelProvider.java:49)
at io.grpc.ManagedChannelProvider.getPriority(ManagedChannelProvider.java:41)
at io.grpc.ServiceProviders.compare(ServiceProviders.java:78)
at java.util.Collections$ReverseComparator2.compare(Collections.java:5178)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1462)
at java.util.Collections.sort(Collections.java:175)
at io.grpc.ServiceProviders.loadAll(ServiceProviders.java:75)
at io.grpc.ServiceProviders.load(ServiceProviders.java:42)
at io.grpc.ManagedChannelProvider.<clinit>(ManagedChannelProvider.java:37)
at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:36)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:185)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:157)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:149)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:151)
at com.google.cloud.monitoring.v3.stub.GrpcMetricServiceStub.create(GrpcMetricServiceStub.java:173)
at com.google.cloud.monitoring.v3.stub.MetricServiceStubSettings.createStub(MetricServiceStubSettings.java:184)
at com.google.cloud.monitoring.v3.MetricServiceClient.<init>(MetricServiceClient.java:158)
at com.google.cloud.monitoring.v3.MetricServiceClient.create(MetricServiceClient.java:139)
at com.google.cloud.monitoring.v3.MetricServiceClient.create(MetricServiceClient.java:130)
at SimpleMetric.main(SimpleMetric.java:7)
关于创建方法:
import com.google.cloud.monitoring.v3.MetricServiceClient;
import java.io.IOException;
public class SimpleMetric {
public static void main(String... args) throws IOException {
MetricServiceClient metricServiceClient = MetricServiceClient.create();
}
}
仅当我添加:
compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:2.5.0'
在我的 gradle 文件中作为依赖项。
plugins {
id 'java'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.cloud:google-cloud-monitoring:1.48.0'
// exception with the dependency below
compile 'com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:2.5.0'
}
我向 Google 报告了 the issue。与此同时,是否有解决方法?
isAndroid
是在 io.grpc.ManagedChannelProvider taken out of grpc-core in version 1.11 中定义的。该错误意味着您正在使用 1.11 之前的 grpc-okhttp 和 1.11 或更高版本的 grpc-core。
google-cloud-monitoring 1.48.0 间接依赖grpc-core 1.13:
com.google.cloud:google-cloud-monitoring:jar:1.48.0:compile
+- com.google.cloud:google-cloud-core:jar:1.48.0:compile
+- com.google.cloud:google-cloud-core-grpc:jar:1.48.0:compile
| +- io.grpc:grpc-protobuf:jar:1.13.1:compile
| | \- io.grpc:grpc-protobuf-lite:jar:1.13.1:compile
| +- io.grpc:grpc-context:jar:1.13.1:compile
+- com.google.api.grpc:proto-google-cloud-monitoring-v3:jar:1.30.0:compile
+- io.grpc:grpc-netty-shaded:jar:1.13.1:compile
| \- io.grpc:grpc-core:jar:1.13.1:compile (version selected from constraint [1.13.1,1.13.1])
| +- com.google.errorprone:error_prone_annotations:jar:2.1.2:compile
| +- io.opencensus:opencensus-api:jar:0.12.3:compile
| \- io.opencensus:opencensus-contrib-grpc-metrics:jar:0.12.3:compile
+- io.grpc:grpc-stub:jar:1.13.1:compile
\- io.grpc:grpc-auth:jar:1.13.1:compile
google-cloud-dataflow-java-sdk-all 2.5.0间接依赖grpc-core 1.2和grpc-okhttp 1.2:
com.google.cloud.dataflow:google-cloud-dataflow-java-sdk-all:jar:2.5.0:compile
+- org.apache.beam:beam-sdks-java-io-google-cloud-platform:jar:2.5.0:compile
| +- io.grpc:grpc-core:jar:1.2.0:compile
| | +- com.google.errorprone:error_prone_annotations:jar:2.0.11:compile
| | +- io.grpc:grpc-context:jar:1.2.0:compile
| | \- com.google.instrumentation:instrumentation-api:jar:0.3.0:compile
| +- com.google.api:gax-grpc:jar:0.20.0:compile
| | +- io.grpc:grpc-protobuf:jar:1.2.0:compile
| | +- com.google.api:api-common:jar:1.1.0:compile
| | +- com.google.auto.value:auto-value:jar:1.2:compile
| | +- com.google.api:gax:jar:1.3.1:compile
| | \- org.threeten:threetenbp:jar:1.3.3:compile
| +- io.grpc:grpc-auth:jar:1.2.0:compile
| +- io.grpc:grpc-netty:jar:1.2.0:compile
| +- io.grpc:grpc-stub:jar:1.2.0:compile
| +- io.grpc:grpc-all:jar:1.2.0:compile
| | +- io.grpc:grpc-okhttp:jar:1.2.0:compile
| | | +- com.squareup.okhttp:okhttp:jar:2.5.0:compile
| | | \- com.squareup.okio:okio:jar:1.6.0:compile
所以基本上数据流已经过时并导致冲突。不再支持数据流 SDK,因为它现在是 Apache Beam。考虑 migrating 解决问题。