簡體   English   中英

使用Kotlin庫作為Java項目中的依賴項

[英]Using Kotlin libraries as dependencies in a Java project

我有一個圖書館項目,為其他項目提供共享功能。 該實現是用Kotlin編寫的。 但是,我確保該庫的公共接口不使用Kotlin提供的任何類。

如果我們將此庫作為依賴項添加到僅Java項目中,它將以可遷移方式提取kotlin-stdlibkotlin-runtime Kotlin-stdlib中的類現在可以(但錯誤地)用於純Java的使用者項目中。

有沒有辦法防止這種類型的泄漏? 我可以想到的一些選擇:

  • 標記Maven中provided kotlin-stdlib-*這會在運行時引起任何問題嗎? ClassNotFoundException等)

  • 陰影+重新kotlin-stdlib-*和/或kotlin-runtime通過陰影,如果我們依賴多個Kotlin庫項目,則可以預見問題。 另外,我不確定這是否會隱藏Kotlin類型。

注意: 在Java代碼使用kotlin庫這個問題這里不適用(標題誤導)。 我特別避免這種情況。

使用implementation關鍵字聲明您的庫依賴項是否足以不傳遞它們而已? 如此處所述 We use the implementation dependency configuration so that we don't expose any of the Kotlin standard library through our API. This has architectural and performance benefits. We use the implementation dependency configuration so that we don't expose any of the Kotlin standard library through our API. This has architectural and performance benefits.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM