簡體   English   中英

Gradle 7 造肥 jar

[英]Gradle 7 create a fat jar

我需要從我的依賴項中創建一個胖 jar ,它不包含 scope compileOnly中的依賴項

dependencies {
   api 'org.slf4j:slf4j-api:1.7.26' // this must be in the jar
   compileOnly 'it.unimi.dsi:fastutil:8.2.1' // this must not be in the jar

    jar {
        from {
            configurations.compileClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
        }
    }
}

當我構建項目時,兩個依賴項都存在於最終的 jar 文件中。 我應該如何從胖 jar 中排除 fastutil?

我嘗試使用runtimeOnly

runtimeOnly 'it.unimi.dsi:fastutil:8.2.1' // this must not be in the jar

但這會導致 fastutil 在編譯期間無法解析。

我正在運行 Java 16 和 Gradle 7.0.2。

使用configurations.runtimeClasspath而不是configurations.compileClasspath compileClasspath包含編譯所需的所有庫,因此包含fastutil 另一方面, runtimeClasspath將庫從配置中排除compileOnly

暫無
暫無

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

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