如何使用sring boot plugin 2.0.x从一个具有不同依赖关系的gradle项目生成2个jar

use*_*383 2 gradle spring-boot gradle-plugin spring-boot-gradle-plugin

我正在尝试将项目迁移到最新版本的Spring和Spring Boot。一切都进展顺利,直到我遇到这个问题。

我们的一个项目会生成最终版本的Jar的两个版本,一个版本可以以最少的依赖项运行,而另一个版本则具有所有额外的模块。

当我使用Spring Boot版本1.5.x时,解决方案很简单,我们使用了“ customConfiguration”

当我使用旧插件时,我的配置文件或多或少都像那样

bootRepackage{ 
    customConfiguration = "addons"
}


dependencies {
    compile "my.org:core-lib:1.0.0"
    addons  "my.org:extra-lib:1.0.0"
}
Run Code Online (Sandbox Code Playgroud)

现在bootRepackagebootJar不持有财产的地方所取代customConfiguration。这是可以在最新版本的插件中完成的吗,如果是的话,有人可以向我指出正确的方向吗?

mis*_*der 5

bootJar是Jar类的子类,因此您可以在此处使用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 
Run Code Online (Sandbox Code Playgroud)

(有一些我不知道的简便方法)