What you need to do is override the processResources configuration:
processResources { def profile = (project.hasProperty('profile') ? project.profile : 'qa').toLowerCase() include "**/application_${profile}.properties" rename { 'application.properties' } }
When replacing the following code fragment, you will get the following result:
$ ./gradlew run -Pprofile=PROD :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :run LOL Profile: PROD BUILD SUCCESSFUL Total time: 3.63 secs $ ./gradlew run -Pprofile=QA :compileJava UP-TO-DATE :processResources :classes :run LOL Profile: QA BUILD SUCCESSFUL Total time: 3.686 secs $ ./gradlew run :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :run LOL Profile: QA BUILD SUCCESSFUL Total time: 3.701 secs
Demo is here .
source share