Eugene G. Ustimenko Eugene G. Ustimenko - 1 month ago 22
YAML Question

How to get properties from gradle.properties into application.yaml

I have multi-project structure with gradle, and use

gradle.properties
file to store environment variables.
Also I use SpringBoot application environment with
application.properties
file at some number of projects.

At
gradle.properties
file I have
api.port=8080
, to get it at
application.properties
file I use
@api.port@
value, i.e.
@..@
placeholders like at official documentation.

Which placeholders I should use if I rename
application.properties
to
application.yaml
?

I tried to use:

server:
port: @api.port@


server:
port: '@api.port@'


server:
port: ${api.port}


If I rename
gradle.properties
into
gradle.yaml
, it occures error with properties reading at
build.gradle

Answer

Answer is simple, earlier I used this with properties files, and now simple read own code more carrier:

processResources {
        filesMatching('application.yaml') {
            filter ReplaceTokens, tokens: [
                    'api.port'         : project.property('api.port')
            ]
        }
    }