Exclude application.properties inside spring boot jar using gradle

Ramprasad V :

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')
}
Bjørn Vester :

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')
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=351687&siteId=1
Recommended