项目是一个SpringBoot2.1.7,使用Minio的Java SDK所触发的完整的报错信息如下:
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
okio.Segment.writeTo(Segment.kt:169)
The following method did not exist:
kotlin.collections.ArraysKt.copyInto([B[BIII)[B
The method's class, kotlin.collections.ArraysKt, is available from the following locations:
jar:file:/Users/houchengwei/maven/repository/org/jetbrains/kotlin/kotlin-stdlib/1.2.71/kotlin-stdlib-1.2.71.jar!/kotlin/collections/ArraysKt.class
It was loaded from the following location:
file:/Users/houchengwei/maven/repository/org/jetbrains/kotlin/kotlin-stdlib/1.2.71/kotlin-stdlib-1.2.71.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of kotlin.collections.ArraysKt
报错的原因
通过报错的描述得知程序调用了一个位于kotlin-stdlib包中的一个不存在的方法kotlin.collections.ArraysKt.copyInto
,该方法是kotlin-stdlib 1.3才出现的。
通过SpringBoot2.1.7的spring-boot-denedencies文件找到了定义kotlin-stdlib所用的版本号为1.2.71。
由于kotlin-stdlib在项目中作为传递依赖,而<dependencyManagement>
又控制了传递依赖的版本,这就导致项目中的kotlin-stdlib的版本被确定成这个1.2.71,该包内没有copyInto
方法,导致程序运行时报错。
解决问题
我们通过直接依赖kotlin-stdlib的方式使项目引入正确版本的kotlin-stdlib包(在项目中的pom.xml的<dependencies>
标签内添加下面的依赖即可):
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.8.21</version>
</dependency>