Note: This is for Maven 3. Earlier versions are (a bit) different.
TL;DR:
"User property" specifies the name of the Maven property that can be used to set a plugin parameter. This allows configuring a plugin from outside the <configuration>
section. Note that this only works if the parameter is not specified in the <configuration>
section (see MNG-4979 - Cannot override configuration parameter from command line).
Maven properties can be set in the POM in the section <properties>
, or on the command line as -DmyProperty=myValue
.
Long version
In Maven, the parameters of a plugin are usually set in an <configuration>
section in the POM. The "parameter name" given in the plugin's documentation is the name to be used in the configuration setting.
For example, the Surefire goal surefire:test has a parameter "failIfNoSpecifiedTests". To set it in the POM, use:
<configuration>
<failIfNoSpecifiedTests>false</failIfNoSpecifiedTests>
</configuration>
However, sometimes it is useful to set a plugin parameter from outside the <configuration>
section, for example to set it on the command line, or in a Maven profile. To allow this, a plugin can also declare that it will read the parameter value from a Maven property (if set). This property is what the docs list as the User property.
The User property for failIfNoSpecifiedTests is surefire.failIfNoSpecifiedTests
. So instead of the <configuration>
section above, one could also use the property surefire.failIfNoSpecifiedTests. For example:
- on the command line, by specifying
-Dsurefire.failIfNoSpecifiedTests=false
- in a POM profile:
<properties> <surefire.failIfNoSpecifiedTests> false </surefire.failIfNoSpecifiedTests> ...
Note that the User property must be declared by the plugin for each parameter, so not all parameters will have one. For example, the parameter basedir
does not have a User property, so can not be set on the command line.
In the source code of the plugin, the parameter name not explicitly declared; it is taken from the name of the Java field. The source code for "failIfNoSpecifiedTests" is:
/**
* Set this to "true" to cause a failure if the none of the tests
* specified in -Dtest=... are run. Defaults to "true".
*
* @since 2.12
*/
@Parameter( property = "surefire.failIfNoSpecifiedTests" )
private Boolean failIfNoSpecifiedTests;
You can see that the parameter name "failIfNoSpecifiedTests" is taken from the field name. The annotation parameter "property" defines the Maven property to use.
<properties />
pom section (source). So for maximum flexibility I'd suggest to specify default user property values in<properties />
, with the possibility to overwrite them on the command line, instead of hardcoding them in the<configuration />
section. E.g. one such propertymaven.compiler.source
andmaven.compiler.target
. – Cordillera