简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM