2

I'm trying to migrate my project to latest versions Spring and Spring Boot. Everything was going smothly till I encounter this problem.

One of our project generates two versions of final Jar, one plain runnable with minimum dependencies, and another one with all extra modules.

While I was using Spring Boot version 1.5.x, then solution was simple, we used 'customConfiguration`

when i was using old plugin, my config file looks more or less like that

bootRepackage{ 
    customConfiguration = "addons"
}


dependencies {
    compile "my.org:core-lib:1.0.0"
    addons  "my.org:extra-lib:1.0.0"
}

now bootRepackage is replaced by bootJar which does not hold property customConfiguration. Is this is possible to do in latest version of plugin, if yest, then could someone point me in right direction please.

user902383
  • 8,420
  • 8
  • 43
  • 63
  • This won't build two separate jars as `bootRepackage` will overwrite the jar that's produced by the `jar` task. If your description of the behaviour is accurate, there must be more to your build's configuration than you've shown here. – Andy Wilkinson Oct 15 '18 at 22:35

1 Answers1

9

bootJar is a sub class of Jar class, so you can use Jar task's configurations here.

Example:

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 

(There can be easier ways do this that I don't know about)

miskender
  • 7,460
  • 1
  • 19
  • 23
  • I hope there is another way because i don't really like this solution. It was so nice and clean in old version. i upvote it and if i cannot find anything better then i will accept it. Thanks – user902383 Oct 15 '18 at 20:38
  • @user902383 why you don't like this solution? There's no other. – Opal Oct 16 '18 at 03:53
  • @Opal maybe i express myself wrong, i don't have a problem with solution but with change which was done to the plugin.way how it was done in old version feels more cleaner. But as i said, if this is only one way i'm happy to accept it – user902383 Oct 16 '18 at 04:21