我需要从不包含作用域compileOnly中的依赖项的依赖项创建一个fat jar
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文件中。我该怎么从胖罐子里排除fastutil呢?
我试着用runtimeOnly
runtimeOnly 'it.unimi.dsi:fastutil:8.2.1' // this must not be in the jar但这会导致fastutil在编译时无法解析。
我运行的是Java16和Gradle 7.0.2。
发布于 2021-05-21 16:58:21
使用configurations.runtimeClasspath而不是configurations.compileClasspath。compileClasspath包含编译所需的所有库,因此也包括fastutil。另一方面,runtimeClasspath从configuration compileOnly中排除了库。
https://stackoverflow.com/questions/67628583
复制相似问题