Setting default values for custom Maven 2 properties

Taylor L's approach works fine, but you don't need the extra profile. You can just declare property values in the POM file.

<project>
  ...
  <properties>
    <!-- Sets the location that Apache Cargo will use to install containers when they are downloaded. 
         Executions of the plug-in should append the container name and version to this path. 
         E.g. apache-tomcat-5.5.20 --> 
    <cargo.container.install.dir>${user.home}/.m2/cargo/containers</cargo.container.install.dir> 
  </properties> 
</project>

You can also set properties in your user settings.xml file in the event that you want each user to be able to set their own defaults. We use this approach to hide credentials that the CI server uses for some plug-ins from regular developers.


You could use something like below:

<profile>
    <id>default</id>
    <properties>
        <env>default</env>
        <myProperty>someValue</myProperty>            
    </properties>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
</profile>

You can have the property default value defined in <build>/<properties> or in a profile like shown below. When you supply the property value on command line with -DmyProperty=anotherValue then it will override the definition from the POM. That is, all definitions of property values in the POM are set only a default value for the properties.

<profile>
    ...
    <properties>
        <myProperty>defaultValue</myProperty>            
    </properties>
    ...
       <configuration>
          <param>${myProperty}</param>
       </configuration>
    ...
</profile>