I need to exclude a specific dependency from springBoots bootJar
gradle task (similar to the provided scope in maven).
I tried a custom configuration, but the dependency-which-should-not-be-in-bootJar
is still included in the resulting jar.
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()
}
I also got an answer from Andy Wilkinson in the spring boot gitter channel which works slightly different but manages to achieve similar.
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)
}
}
Thank you Andy =)
You can actually use compileOnly for your dependency with gradle > 2.12
dependencies {
// ...
compileOnly "dependency-which-should-not-be-in-bootJar"
}
You will still have it for test + runtime, but not in the final built jar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With