Default build profile for Maven

MavenMaven Profiles

Maven Problem Overview


I have added profiling to my Maven project.

        <profile>
            <id>da</id>                
        </profile>
        <profile>
            <id>live</id>
        </profile>
        <profile>
            <id>dev</id>
        </profile>

When I give the command mvn clean install without specifying the build profile. I need the dev profile to be build by default.

How can I achieve this?

Maven Solutions


Solution 1 - Maven

By using the attribute activeByDefault you will be able to select a default profile in Maven when no other profile is selected with the -P parameter.

<profiles>
    <profile>
        <id>da</id>                
    </profile>
    <profile>
        <id>live</id>
    </profile>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
</profiles>
    

See Maven Introduction to Profiles documentation

Solution 2 - Maven

You can also activate specific profile by running

mvn clean install -Pprod  

or

mvn clean install -Pdev

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIsuruView Question on Stackoverflow
Solution 1 - MavenFredrikOView Answer on Stackoverflow
Solution 2 - MavenPravin BansalView Answer on Stackoverflow