Maven Profiles - bahkified/Notes GitHub Wiki

Profiles can be defined in any of three places: in the global maven settings, in the user maven settings, or in the project pom. Profiles declared in the maven settings are not considered portable. To declare profiles in the pom:

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <unhandled.error.message>Error in development environment!</unhandled.error.message>
            </properties>
        </profile>

        <profile>
            <id>prod</id>
            <activation>
                <property>
                    <name>environment</name>
                    <value>prod</value>
                </property>
            </activation>
            <properties>
                <unhandled.error.message>An error has occurred.</unhandled.error.message>
            </properties>
        </profile>
    </profiles>

This snippet creates two profiles in the pom. The dev profile will be active if no profile is specified. To activate the prod profile, the maven command must be run with the -P prod argument, or by setting the environment property: -Denvironment=prod.

These two profiles define different properties that can be filtered to project resources.

Example

mvn clean install -Denvironment=prod

Resources

⚠️ **GitHub.com Fallback** ⚠️