Spring boot 从springBoots`bootJar`gradle任务中排除特定依赖项
我需要从springBootsSpring boot 从springBoots`bootJar`gradle任务中排除特定依赖项,spring-boot,gradle,dependency-management,executable-jar,Spring Boot,Gradle,Dependency Management,Executable Jar,我需要从springBootsbootJargradle任务中排除特定的依赖项(类似于maven中提供的范围) 我尝试了一个自定义配置,但是结果jar中仍然包含了不应该在bootJar中的依赖项 configurations{ provided implementation.extendsFrom provided } dependencies { // ... provided "dependency-which-should-not-be-in-bootJa
bootJar
gradle任务中排除特定的依赖项(类似于maven中提供的范围)
我尝试了一个自定义配置,但是结果jar中仍然包含了不应该在bootJar中的依赖项
configurations{
provided
implementation.extendsFrom provided
}
dependencies {
// ...
provided "dependency-which-should-not-be-in-bootJar"
}
jar {
from configurations.compile - configurations.provided
from configurations.runtime
}
bootJar {
from configurations.compile - configurations.provided
from configurations.runtime
launchScript()
}
实际上,您可以对gradle>2.12的依赖项使用compileOnly
dependencies {
// ...
compileOnly "dependency-which-should-not-be-in-bootJar"
}
您仍然可以在test+runtime中使用它,但不能在最终构建的jar中使用。我还从spring boot gitter通道中获得了一个答案,该通道的工作原理略有不同,但实现了类似的功能
configurations {
custom
runtime.extendsFrom custom
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
custom 'com.h2database:h2'
}
bootJar {
exclude {
configurations.custom.resolvedConfiguration.files.contains(it.file)
}
}
谢谢Andy=)bootJar
默认包含运行时类路径。它继承自实现
,您已将其配置为从提供的
扩展而来,运行时类路径包含您提供的依赖项,因此它包含在fat jar中。我还尝试将我的提供的
更改为提供的运行时
,并让它从运行时
扩展。之后,我尝试配置引导jar,用从配置覆盖运行时包含。运行时-configurations.providedRuntime
,我认为它应该可以工作,但实际上不行。你能给我指出正确的方向吗?如何正确地将依赖项从jar打包中排除。在我的例子中,我还必须添加testRuntime
,但它在thx中工作得非常好。它不适用于类路径文件夹:resolvedConfiguration.files
仍然包含文件夹java.io.File
,而it.file
是该文件夹的子文件夹这对我有用:configurations.custom.resolvedConfiguration.files.find{customEntry->it.file.toPath().startsWith(customEntry.toPath())}=空