Kotlin 1.4.30 Apache beam 编译错误

Kotlin 1.4.30 Apache beam compilation error

我正在尝试将 Apache Beam 数据流管道更新到最新的 kotlin 版本 1.4.30,该管道目前是 运行 kotlin 1.4.21,但是一旦我升级 build.gradle 版本 1.4.30编译失败并出现此异常:

java.lang.IllegalStateException: Could not read class: VirtualFile: /Users/stefanomassera/.gradle/caches/modules-2/files-2.1/org.apache.beam/beam-sdks-java-core/2.26.0/b57f8fa5ae66564c7ffafde34b690057f471bfa8/beam-sdks-java-core-2.26.0.jar!/org/apache/beam/sdk/options/PipelineOptions.class
    at org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaClass.<init>(BinaryJavaClass.kt:120)
    at org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaClass.<init>(BinaryJavaClass.kt:34)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCliJavaFileManagerImpl.findClass(KotlinCliJavaFileManagerImpl.kt:115)
    at org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade$CliFinder.findClass(KotlinJavaPsiFacade.java:484)
  ... omissis for brevity
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: Wildcard mast have a bound for annotation of WILDCARD_BOUND position
    at org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaAnnotation$Companion.computeTargetType$resolution_common_jvm(Annotations.kt:188)
    at org.jetbrains.kotlin.load.java.structure.impl.classFiles.AnnotationsAndParameterCollectorMethodVisitor.visitTypeAnnotation$getTargetType(Annotations.kt:111)
    at org.jetbrains.kotlin.load.java.structure.impl.classFiles.AnnotationsAndParameterCollectorMethodVisitor.visitTypeAnnotation(Annotations.kt:117)
    at org.jetbrains.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1427)
    at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:719)
    at org.jetbrains.org.objectweb.asm.ClassReader.accept(ClassReader.java:402)
    at org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaClass.<init>(BinaryJavaClass.kt:115)
    ... 101 more

我还尝试了一个空白的虚拟项目,只是为了验证它是否与当前的 kotlin 和 apache beam 存在兼容性错误,这似乎是一个兼容性问题,这里是我的虚拟测试

main.kt

package org.example

import org.apache.beam.sdk.Pipeline
import org.apache.beam.sdk.options.PipelineOptionsFactory

class DummyPipeline {
    fun main(args: Array<String>) {
        val options = PipelineOptionsFactory.fromArgs(*args)
            .withValidation()
            .`as`(DummyPipelineOptions::class.java)
        val pipeline = Pipeline.create(options)
        pipeline.run()
    }
}

build.gradle

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.4.30' //<-- do not build
    //id 'org.jetbrains.kotlin.jvm' version '1.4.21' // <-- correctly build
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
    implementation "org.apache.beam:beam-sdks-java-io-google-cloud-platform:2.26.0"
    runtimeOnly "org.apache.beam:beam-runners-direct-java:2.26.0"
}

有人解决了这个兼容性问题吗?

由Kotlin编译器引起。

抱歉造成麻烦,我目前正在编译器方面修复它。该修复程序将在 Kotlin 1.5-M1 中提供。

不幸的是,这里没有正常的解决方法,因为问题发生在读取 class 个文件时(无法排除读取 class 个文件的机制中有问题的逻辑)。