Spring boot build variants Profile-specific properties with gradle

I have different configs application-prod.properties and application-beta.properties files I run it by: -Dspring.profiles.active=beta or -Dspring.profiles.active=prod

It works but also I use gradle:

war {
    baseName = 'beta'
    version = '0.0.1-SNAPSHOT'

I want to use variable from application.properties and set to baseName. How to pass variable from application.properties to baseName in gradle file?

on code level I do it like this:

private String baseName;

1 answer

  • answered 2017-01-11 14:17 Vampire

    Just read in the properties file and use it, a Gradle script is Groovy so you can use any Groovy code like:

    Properties applicationProperties = new Properties()
    file('application.properties').withInputStream {
    war {
        baseName = applicationProperties.baseName