My project is spring boot with gradle. My goal is to have spring boot generate 2 different boot jars. The first jar is the typical jar created today which would be used in production systems. The second jar would be used by other systems for integration testing. The second jar would have a different set of configuration and dependencies. Has anyone else done this? I did not see any simple configuration for the bootJar task nor was i successful trying to create my own task based on bootJar.
UPDATE: Below is the solution which worked based upon Francisco Mateo's answer.
configurations {
integrationImplementation.extendsFrom implementation
integrationRuntimeOnly.extendsFrom runtimeOnly
//...
}
dependencies {
// ...
integrationRuntimeOnly 'com.h2database:h2'
// ...
}
sourceSets {
integration {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
tasks.register("integrationBootJar", BootJar) {
description = "Assembles an executable JAR archive to be used for integration tests of other projects containing the main classes, their dependencies, and any other integrationImplementation or integrationRuntimeOnly dependencies."
group = 'build'
classpath = sourceSets.main.runtimeClasspath.plus(sourceSets["integration"].runtimeClasspath)
mainClass.set("${jarMainClass}") // TODO can pull from bootJarMainClassName or bootRunMainClassName like bootJar?
archiveClassifier.set("integration")
shouldRunAfter bootJar
}
assemble.dependsOn integrationBootJar