Gradle 在将 Spring Boot 2.0.0.RELEASE 与 google-cloud-pubsub 一起



我有一个在最新的 2.0.0.M5 上运行的 Spring Boot 应用程序,带有 google-cloud-pubsub:0.0.28 .当我将 Spring 提升到 2.0.0.RELEASE 时,Spring 无法启动此错误:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class io.netty.handler.ssl.OpenSslEngine
at io.netty.handler.ssl.OpenSslContext.newEngine0(OpenSslContext.java:49)
at io.netty.handler.ssl.ReferenceCountedOpenSslContext.newEngine(ReferenceCountedOpenSslContext.java:358)
at io.grpc.netty.ProtocolNegotiators$TlsNegotiator$1.handlerAdded(ProtocolNegotiators.java:306)
at io.netty.channel.DefaultChannelPipeline.callHandlerAdded0(DefaultChannelPipeline.java:617)
... 19 common frames omitted

我注意到,在提升了 Spring 版本之后,Gradle 开始拉入io.netty:netty-codec-http2:4.1.22而不是像 M5 版本的 Spring 那样4.1.16

我的build.gradle

 buildscript {
    ext.kotlinVersion = '1.2.0'
    ext.springBootVersion = '2.0.0.RELEASE'
    ext.junitPlatformVersion = '1.0.2'
    ext.cucumberVersion = '2.3.1'
    repositories {
        mavenCentral()
        jcenter()
        maven { url "https://repo.spring.io/milestone" }
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "http://dl.bintray.com/kotlin/kotlin-eap-1.2" }
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
        classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}"
        classpath "org.junit.platform:junit-platform-gradle-plugin:${junitPlatformVersion}"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}
apply {
    plugin 'kotlin'
    plugin 'kotlin-spring'
    plugin 'org.springframework.boot'
    plugin "org.junit.platform.gradle.plugin"
    plugin 'io.spring.dependency-management'
}
sourceCompatibility = 1.8
compileKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "1.8"
    }
}
junitPlatform {
    filters {
        engines {
            include "spek"
        }
    }
}
configurations {
    ktlint
    acceptanceCompile.extendsFrom compile
    acceptanceRuntime.extendsFrom runtime
}
repositories {
    mavenCentral()
    jcenter()
    maven { url "https://repo.spring.io/milestone" }
    maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlinVersion}"
    compile "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
    compile "com.google.cloud:google-cloud-pubsub:0.28.0-beta"
}

依赖树:

:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.2.0
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.2.0
|    |    --- org.jetbrains:annotations:13.0
|    --- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.0
|         --- org.jetbrains.kotlin:kotlin-stdlib:1.2.0 (*)
+--- org.jetbrains.kotlin:kotlin-reflect:1.2.0
|    --- org.jetbrains.kotlin:kotlin-stdlib:1.2.0 (*)
--- com.google.cloud:google-cloud-pubsub:0.28.0-beta
     +--- io.netty:netty-tcnative-boringssl-static:2.0.6.Final
     +--- com.google.cloud:google-cloud-core:1.10.0
     |    +--- com.google.guava:guava:20.0
     |    +--- joda-time:joda-time:2.9.2 -> 2.9.9
     |    +--- org.json:json:20160810
     |    +--- com.google.http-client:google-http-client:1.23.0
     |    |    +--- com.google.code.findbugs:jsr305:1.3.9 -> 3.0.0
     |    |    --- org.apache.httpcomponents:httpclient:4.0.1 -> 4.5.5
     |    |         +--- org.apache.httpcomponents:httpcore:4.4.9
     |    |         --- commons-codec:commons-codec:1.10 -> 1.11
     |    +--- com.google.code.findbugs:jsr305:3.0.0
     |    +--- com.google.api:api-common:1.2.0
     |    |    +--- com.google.code.findbugs:jsr305:3.0.0
     |    |    --- com.google.guava:guava:19.0 -> 20.0
     |    +--- com.google.api:gax:1.14.0
     |    |    +--- com.google.auto.value:auto-value:1.2
     |    |    +--- com.google.code.findbugs:jsr305:3.0.0
     |    |    +--- com.google.guava:guava:20.0
     |    |    +--- org.threeten:threetenbp:1.3.3
     |    |    +--- com.google.auth:google-auth-library-oauth2-http:0.9.0
     |    |    |    +--- com.google.auth:google-auth-library-credentials:0.9.0
     |    |    |    +--- com.google.http-client:google-http-client:1.19.0 -> 1.23.0 (*)
     |    |    |    +--- com.google.http-client:google-http-client-jackson2:1.19.0
     |    |    |    |    +--- com.google.http-client:google-http-client:1.19.0 -> 1.23.0 (*)
     |    |    |    |    --- com.fasterxml.jackson.core:jackson-core:2.1.3 -> 2.9.4
     |    |    |    --- com.google.guava:guava:19.0 -> 20.0
     |    |    --- com.google.api:api-common:1.2.0 (*)
     |    +--- com.google.protobuf:protobuf-java-util:3.4.0
     |    |    +--- com.google.protobuf:protobuf-java:3.4.0
     |    |    +--- com.google.guava:guava:19.0 -> 20.0
     |    |    --- com.google.code.gson:gson:2.7 -> 2.8.2
     |    +--- com.google.api.grpc:proto-google-common-protos:1.0.0
     |    |    --- com.google.protobuf:protobuf-java:3.3.0 -> 3.4.0
     |    --- com.google.api.grpc:proto-google-iam-v1:0.1.24
     |         +--- com.google.protobuf:protobuf-java:3.3.0 -> 3.4.0
     |         +--- com.google.api:api-common:1.1.0 -> 1.2.0 (*)
     |         --- com.google.api.grpc:proto-google-common-protos:1.0.0 (*)
     +--- com.google.cloud:google-cloud-core-grpc:1.10.0
     |    +--- io.netty:netty-tcnative-boringssl-static:2.0.6.Final
     |    +--- com.google.auth:google-auth-library-credentials:0.9.0
     |    +--- com.google.cloud:google-cloud-core:1.10.0 (*)
     |    +--- com.google.guava:guava:20.0
     |    +--- com.google.protobuf:protobuf-java:3.4.0
     |    +--- com.google.protobuf:protobuf-java-util:3.4.0 (*)
     |    +--- io.grpc:grpc-protobuf:1.7.0
     |    |    +--- io.grpc:grpc-core:1.7.0
     |    |    |    +--- io.grpc:grpc-context:1.7.0
     |    |    |    +--- com.google.guava:guava:19.0 -> 20.0
     |    |    |    +--- com.google.errorprone:error_prone_annotations:2.0.19
     |    |    |    +--- com.google.code.findbugs:jsr305:3.0.0
     |    |    |    +--- com.google.instrumentation:instrumentation-api:0.4.3
     |    |    |    |    +--- com.google.code.findbugs:jsr305:3.0.0
     |    |    |    |    --- com.google.guava:guava:19.0 -> 20.0
     |    |    |    --- io.opencensus:opencensus-api:0.6.0
     |    |    |         --- com.google.guava:guava:19.0 -> 20.0
     |    |    +--- com.google.protobuf:protobuf-java:3.4.0
     |    |    +--- com.google.guava:guava:19.0 -> 20.0
     |    |    +--- com.google.protobuf:protobuf-java-util:3.4.0 (*)
     |    |    +--- com.google.api.grpc:proto-google-common-protos:0.1.9 -> 1.0.0 (*)
     |    |    --- io.grpc:grpc-protobuf-lite:1.7.0
     |    |         +--- io.grpc:grpc-core:1.7.0 (*)
     |    |         --- com.google.guava:guava:19.0 -> 20.0
     |    +--- io.grpc:grpc-context:1.7.0
     |    +--- io.grpc:grpc-netty:1.7.0
     |    |    +--- io.grpc:grpc-core:[1.7.0] -> 1.7.0 (*)
     |    |    +--- io.netty:netty-codec-http2:[4.1.16.Final] -> 4.1.22.Final
     |    |    |    +--- io.netty:netty-codec-http:4.1.22.Final
     |    |    |    |    --- io.netty:netty-codec:4.1.22.Final
     |    |    |    |         --- io.netty:netty-transport:4.1.22.Final
     |    |    |    |              +--- io.netty:netty-buffer:4.1.22.Final
     |    |    |    |              |    --- io.netty:netty-common:4.1.22.Final
     |    |    |    |              --- io.netty:netty-resolver:4.1.22.Final
     |    |    |    |                   --- io.netty:netty-common:4.1.22.Final
     |    |    |    --- io.netty:netty-handler:4.1.22.Final
     |    |    |         +--- io.netty:netty-buffer:4.1.22.Final (*)
     |    |    |         +--- io.netty:netty-transport:4.1.22.Final (*)
     |    |    |         --- io.netty:netty-codec:4.1.22.Final (*)
     |    |    --- io.netty:netty-handler-proxy:4.1.16.Final -> 4.1.22.Final
     |    |         +--- io.netty:netty-transport:4.1.22.Final (*)
     |    |         +--- io.netty:netty-codec-socks:4.1.22.Final
     |    |         |    --- io.netty:netty-codec:4.1.22.Final (*)
     |    |         --- io.netty:netty-codec-http:4.1.22.Final (*)
     |    +--- io.grpc:grpc-stub:1.7.0
     |    |    --- io.grpc:grpc-core:1.7.0 (*)
     |    +--- io.grpc:grpc-auth:1.7.0
     |    |    +--- io.grpc:grpc-core:[1.7.0] -> 1.7.0 (*)
     |    |    --- com.google.auth:google-auth-library-credentials:0.4.0 -> 0.9.0
     |    --- com.google.api:gax-grpc:1.14.0
     |         +--- com.google.auto.value:auto-value:1.2
     |         +--- com.google.code.findbugs:jsr305:3.0.0
     |         +--- com.google.api:gax:1.14.0 (*)
     |         +--- io.grpc:grpc-netty:1.7.0 (*)
     |         +--- io.grpc:grpc-stub:1.7.0 (*)
     |         +--- io.grpc:grpc-auth:1.7.0 (*)
     |         +--- io.grpc:grpc-protobuf:1.7.0 (*)
     |         +--- com.google.guava:guava:20.0
     |         +--- org.threeten:threetenbp:1.3.3
     |         +--- com.google.auth:google-auth-library-oauth2-http:0.9.0 (*)
     |         +--- com.google.auth:google-auth-library-credentials:0.9.0
     |         +--- com.google.api.grpc:proto-google-common-protos:1.0.0 (*)
     |         --- com.google.api:api-common:1.2.0 (*)
     +--- com.google.api.grpc:proto-google-cloud-pubsub-v1:0.1.24
     |    +--- com.google.api.grpc:proto-google-iam-v1:0.1.24 (*)
     |    +--- com.google.protobuf:protobuf-java:3.3.0 -> 3.4.0
     |    +--- com.google.api:api-common:1.1.0 -> 1.2.0 (*)
     |    --- com.google.api.grpc:proto-google-common-protos:1.0.0 (*)
     +--- com.google.api.grpc:grpc-google-cloud-pubsub-v1:0.1.24
     |    +--- com.google.api.grpc:proto-google-cloud-pubsub-v1:0.1.24 (*)
     |    +--- io.grpc:grpc-stub:1.7.0 (*)
     |    --- io.grpc:grpc-protobuf:1.7.0 (*)
     +--- io.grpc:grpc-netty:1.7.0 (*)
     +--- io.grpc:grpc-stub:1.7.0 (*)
     --- io.grpc:grpc-auth:1.7.0 (*)
(*) - dependencies omitted (listed previously)
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

我在build.gradle中尝试了各种排除。关于如何让 Gradle 拉入4.1.16 io.netty而不是4.1.22的任何想法?

如果可以升级使用 gRPC 1.9.0 的 Pub/Sub 客户端版本,可能会更好。或者,只需将 gRPC 版本升级到 1.9.0。使用较新的 gRPC 版本,可以排除 grpc-netty 依赖项并包含 grpc-netty-shadeency。这应该避免与Spring Boot的Netty发生冲突。

我们也在积极研究 cloud.spring.io/spring-cloud-gcp/可以与Spring Boot 2一起使用,它将能够引入正确的依赖项。

相关内容

最新更新