Search code examples
pom.xmlmulesoftmule4

How can I access POM file properties inside mule configuration files?


Lets say I needed to access a groupId inside the properties tag of my POM file. How can i access that in my mule configuration file.

I tried to access it like ${pom.properties.app.groupId} but it didn't work. Any ideas?

enter image description here enter image description here


Solution

  • This question has been asked before at Mule 4 : Is there a way to refer Maven POM properties from a Mule Flow? and probably others.

    I'll repeat my answer here because Stackoverflow doesn't allow me to mark this one as a duplicate.

    That's because Maven properties do not exists anymore when the application is executed.

    You can use some Maven plugins to replace values in a properties files, that can be used inside the application. For example the Maven Resources plugin. Be careful of not override properties inside other files, like the XML Mule configurations of the application.

    Update: I have created an example:

    Assume that you have a properties file called config.properties in which you want to put the value of Maven property name:

    a=1
    b=${some.property}
    

    Then you can enable Maven property filtering in just that file with:

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>config.properties</include>
                </includes>
            </resource>     
        </resources>
        ...
    

    My blog has a longer explanation of this example: https://medium.com/@adobni/using-maven-properties-as-mule-properties-3f1d0db62c43