問題背景
項目中需要引入minio,添加了如下依賴
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.2</version>
</dependency>
結(jié)果運(yùn)行報錯:
Caused by: java.lang.RuntimeException: Unsupported OkHttp library found. Must use okhttp >= 4.8.1
at io.minio.S3Base.<clinit>(S3Base.java:106)
... 50 common frames omitted
Caused by: java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B
at okio.Segment.writeTo(Segment.kt:169)
at okio.Segment.compact(Segment.kt:152)
at okio.Buffer.write(Buffer.kt:1854)
at okio.Buffer.read(Buffer.kt:1865)
at okio.Buffer.writeAll(Buffer.kt:1655)
at okio.Options$Companion.buildTrieRecursive(Options.kt:187)
at okio.Options$Companion.buildTrieRecursive(Options.kt:174)
at okio.Options$Companion.buildTrieRecursive$default(Options.kt:113)
at okio.Options$Companion.of(Options.kt:72)
at okhttp3.internal.Util.<clinit>(Util.kt:72)
at okhttp3.RequestBody$Companion.create(RequestBody.kt:145)
at okhttp3.RequestBody$Companion.create$default(RequestBody.kt:143)
at okhttp3.RequestBody.create(RequestBody.kt)
at io.minio.S3Base.<clinit>(S3Base.java:104)
... 50 common frames omitted
解決過程
1.?看到Unsupported OkHttp library found. Must use okhttp >= 4.8.1,以為是之前引入的okhttp的版本太低,于是將?okhttp?升到?4.8.1?,還是報同樣錯誤
2. 上網(wǎng)查了一下,說需要在minio的依賴中排除okhttp依賴,再引入所需依賴,如下所示
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.2</version>
<exclusions>
<exclusion>
<artifactId>okhttp</artifactId>
<groupId>com.squareup.okhttp3</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.8.1</version>
</dependency>
還是不行。這時仍堅定地以為是okhttp的版本沖突導(dǎo)致的。
3. 繼續(xù)查呀查,學(xué)會看依賴樹了。發(fā)現(xiàn)此時okhttp應(yīng)該沒有沖突了。
那是什么原因呢?突然,注意到了報錯信息中的NoSuchMethodError: kotlin.collections.ArraysKt.copyInto。于是搜索kotlin,發(fā)現(xiàn)最終元兇。應(yīng)該是okhttp中的okio依賴的 kotlin 是1.3.70版本的,而實(shí)際依賴的?kotlin 是1.2.71版本的,所以在ArraysKt中找不到copyInto方法。
解決辦法
在 minio 的依賴中排除 okhttp 依賴,再單獨(dú)引入所需的 okhttp 依賴。在引入的 okhttp 的依賴中排除 kotlin? 的依賴,再單獨(dú)引入所需 kotlin 依賴。
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.5.2</version>
<exclusions>
<exclusion>
<artifactId>okhttp</artifactId>
<groupId>com.squareup.okhttp3</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.8.1</version>
<exclusions>
<exclusion>
<artifactId>kotlin-stdlib</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.3.70</version>
</dependency>
后話?
作為maven白癡,之前遇到依賴沖突的問題都不知從何下手。這次在尋找解決辦法的過程中,對maven的了解更加深入了。了解到之前okhttp錯誤依賴的kotlin版本可能是在spring的 DependencyManagement中指定的,解決辦法就是先排除這個依賴,再單獨(dú)添加依賴并指定版本。
參考資料
1.?springboot項目 minio okhttp版本依賴問題_unsupported okhttp library found. must use okhttp -CSDN博客文章來源:http://www.zghlxwxcb.cn/news/detail-858209.html
2.?記錄Maven 依賴包版本號奇奇怪怪的問題 - okhttp3、okio 版本指定無效_okio maven-CSDN博客文章來源地址http://www.zghlxwxcb.cn/news/detail-858209.html
到了這里,關(guān)于springboot引入minio導(dǎo)致的okhttp、kotlin的版本沖突問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!