[英]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.