javamaven

How does one use a Maven profile?


I am new to maven and read bit about profiles at this and other resources

What i understood we use profile if we want to do override some default values or do some specific stuff.

In my legacy project i can see below profile where i just see overriding app.mode property. But i do not see using this property further any where in build. I am sure what special being done here?

<profiles>
        <profile>
            <id>dev</id>
            <properties>
                <app.mode>dev</app.mode>
            </properties>
        </profile>
</profiles>

Solution

  • The profile would be activated if you pass -Pdev on the command line to Maven.

    mvn -Pdev
    

    See Introduction to Build Profiles

    What this profile does is change the setting of the property app.mode from whatever it was before to dev. You will want to search your pom file (and the poms of any modules) for uses of $[app.mode} to see what's happening -- if anything.

    Maven properties do not pass into Spring automatically, but it's not uncommon to find configuration in to re-export them as system properties to make them visible to Spring. This typically happens in the configuration for surefire and failsafe, but it's explicit, you'll still see ${app.mode} in a pom somewhere.