如何使用 spring boot 插件 2.0.x 从一个具有不同依赖项的 gradle 项目生成 2 个 jar
How to generate 2 jars from one gradle project with different dependencies using sring boot plugin 2.0.x
我正在尝试将我的项目迁移到最新版本 Spring 和 Spring Boot.一切都很顺利,直到我遇到这个问题。
我们的一个项目生成了两个版本的最终 Jar,一个具有最小依赖性的普通可运行版本,另一个具有所有额外模块。
当我使用 Spring 引导版本 1.5.x 时,解决方案很简单,我们使用了“customConfiguration”
当我使用旧插件时,我的配置文件看起来或多或少像那样
bootRepackage{
customConfiguration = "addons"
}
dependencies {
compile "my.org:core-lib:1.0.0"
addons "my.org:extra-lib:1.0.0"
}
现在 bootRepackage
被 bootJar
取代,后者不支持 属性 customConfiguration
。这是否可以在最新版本的插件中执行,如果可以,请有人指出我正确的方向。
bootJar 是 Jar class 的子 class,因此您可以在此处使用 Jar 任务的配置。
示例:
configurations {
//second jar's configuration
addons
}
dependencies {
....
// sample dependency
addons group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.1'
}
task customJar(type: org.springframework.boot.gradle.tasks.bundling.BootJar){
baseName = 'custom-spring-boot'
version = '0.1.0'
mainClassName = 'hello.Application'
from {
// this is your second jar's configuration
configurations.addons.collect { it.isDirectory() ? it : zipTree(it) }
}
with bootJar
}
// add a dependency to create both jars with gradle bootJar Command
bootJar.dependsOn customJar
(还有我不知道的更简单的方法)
我正在尝试将我的项目迁移到最新版本 Spring 和 Spring Boot.一切都很顺利,直到我遇到这个问题。
我们的一个项目生成了两个版本的最终 Jar,一个具有最小依赖性的普通可运行版本,另一个具有所有额外模块。
当我使用 Spring 引导版本 1.5.x 时,解决方案很简单,我们使用了“customConfiguration”
当我使用旧插件时,我的配置文件看起来或多或少像那样
bootRepackage{
customConfiguration = "addons"
}
dependencies {
compile "my.org:core-lib:1.0.0"
addons "my.org:extra-lib:1.0.0"
}
现在 bootRepackage
被 bootJar
取代,后者不支持 属性 customConfiguration
。这是否可以在最新版本的插件中执行,如果可以,请有人指出我正确的方向。
bootJar 是 Jar class 的子 class,因此您可以在此处使用 Jar 任务的配置。
示例:
configurations {
//second jar's configuration
addons
}
dependencies {
....
// sample dependency
addons group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.1'
}
task customJar(type: org.springframework.boot.gradle.tasks.bundling.BootJar){
baseName = 'custom-spring-boot'
version = '0.1.0'
mainClassName = 'hello.Application'
from {
// this is your second jar's configuration
configurations.addons.collect { it.isDirectory() ? it : zipTree(it) }
}
with bootJar
}
// add a dependency to create both jars with gradle bootJar Command
bootJar.dependsOn customJar
(还有我不知道的更简单的方法)