Migrating from Maven to Gradle and are using Spring. How do we get gradle properties into Spring?

We use Springs PropertiesFactoryBean and PropertySourcesPlaceholderConfigurer to grab layered properties from the filesystem. Our POM.xml declares bar and then in our .property files we can reference the variable via a placeholder ${foo} ?Spring? magically replaces the value of ${foo} with the value declared in the POM.xml (I’m not 100% sure how this works)

How can we declare a property in build.gradle or gradle.properties or settings.gradle and have that brought into the placeholders in our Spring PropertyBean?




<bean id="configProperties"
        <property name="locations">
      <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        <property name="properties" ref="configProperties" />

pom.xml (snippet)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

I suspect that it is actually Maven Resource Filtering replacing your property values:


If so, then Gradle has a similar mechanism built into any Copy task


Note that ‘processResources’ from the Java plugin is such a Copy task

Holy smokes…THANK YOU Perryn.

Another engineer set this stuff up… and I just wasn’t grokking it until today. It all makes perfect sense now. I was missing the key config in our giant POM.xml that was accomplishing this:


Wahoo! The pieces are starting to fall together…