[英]Using Kotlin libraries as dependencies in a Java project
我有一個圖書館項目,為其他項目提供共享功能。 該實現是用Kotlin編寫的。 但是,我確保該庫的公共接口不使用Kotlin提供的任何類。
如果我們將此庫作為依賴項添加到僅Java項目中,它將以可遷移方式提取kotlin-stdlib
和kotlin-runtime
。 Kotlin-stdlib中的類現在可以(但錯誤地)用於純Java的使用者項目中。
有沒有辦法防止這種類型的泄漏? 我可以想到的一些選擇:
標記Maven中provided
kotlin-stdlib-*
:這會在運行時引起任何問題嗎? ( ClassNotFoundException
等)
陰影+重新kotlin-stdlib-*
和/或kotlin-runtime
:通過陰影,如果我們依賴多個Kotlin庫項目,則可以預見問題。 另外,我不確定這是否會隱藏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.