Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding application.yml during Gradle processResources gives MissingPropertyException

To replaces properties in my Spring Boot application.yml I've added:

processResources {
    filesMatching("**/application.yml") {
        expand(project.properties)
    }
}

The replacement fails but gives a MissingPropertyException:

Caused by: groovy.lang.MissingPropertyException: No such property: OPENSHIFT_MYSQL_DB_HOST for class: SimpleTemplateScript1
        at SimpleTemplateScript1.run(SimpleTemplateScript1.groovy:49)
        at org.gradle.api.internal.file.copy.FilterChain$3.transform(FilterChain.java:95)
        at org.gradle.api.internal.file.copy.FilterChain$3.transform(FilterChain.java:84)
        at org.gradle.api.internal.ChainingTransformer.transform(ChainingTransformer.java:37)
        at org.gradle.api.internal.file.copy.FilterChain.transform(FilterChain.java:39)
        at org.gradle.api.internal.file.copy.FilterChain.transform(FilterChain.java:46)
        at org.gradle.api.internal.file.copy.DefaultFileCopyDetails.open(DefaultFileCopyDetails.java:86)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:56)
        at org.gradle.api.internal.file.copy.DefaultFileCopyDetails.copyTo(DefaultFileCopyDetails.java:94)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyFile(AbstractFileTreeElement.java:93)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:74)
        ... 81 more

Originally my application.yml contained:

url: jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST}:${OPENSHIFT_MYSQL_DB_PORT}/${OPENSHIFT_APP_NAME}

Note these Openshift variables are only know on Openshift production environment but not when running locally in dev mode.

As stated on http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.Copy.html: You can also include arbitrary Groovy code in the file, such as ${version ?: 'unknown'} so I changed my application.yml to:

url: jdbc:mysql://${OPENSHIFT_MYSQL_DB_HOST ?: ''}:${OPENSHIFT_MYSQL_DB_PORT ?: ''}/${OPENSHIFT_APP_NAME ?: ''}

But this gives the same MissingPropertyException. Am I missing something here?

like image 347
Marcel Overdijk Avatar asked Mar 19 '15 19:03

Marcel Overdijk


1 Answers

The Gradle expand ${..} style conflicts with the same Spring property placeholder style and therefor needs to be escaped like \${..}. This is added to Spring Boot docs now: https://github.com/spring-projects/spring-boot/commit/c0c67f2593dbfd17aa304b43f4da3a3678fa58eb

like image 164
Marcel Overdijk Avatar answered Nov 25 '22 09:11

Marcel Overdijk