Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude application.properties inside spring boot jar using gradle

I am trying to exclude application.properties from the fat jar created by gradle for a Springboot application. I can do it in maven. Gradle is the preferred build tool for the project. I tried to used exclude in the 'jar' task. It is not working. Any other suggestions ?

plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'}
group = 'com.prasad'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
     mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}
jar {
     exclude('application.properties')
     //tried this too exclude('src/main/resources/application.properties')
}
like image 492
Ramprasad V Avatar asked Sep 17 '26 07:09

Ramprasad V


1 Answers

Excluding resources is usually the wrong approach. I would simply remove it from src/main/resources. If you use it for testing purposes, put it in src/test/resources. If you use it for the local bootRun task, you can configure that particular task with a path to a application.properties file which you can put somewhere else.

However, if you really like to exclude it, the pattern is correct. You are just not excluding it from the bootJar (fat jar) but only the normal jar (which is disabled by default when using the Spring Boot plugin). Try with:

bootJar {
     exclude('application.properties')
}
like image 108
Bjørn Vester Avatar answered Sep 20 '26 00:09

Bjørn Vester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!