Custom properties or variables are useful to keep your Maven pom.xml file more easy to read and maintain.

File : pom.xml

<project>
...
  <properties>
     <my.plugin.version>1.5</my.plugin.version>
  </properties>
...
</project>

In above pom.xml, you can refer “my.plugin.version” via code ${my.plugin.version}.

Example 1

A classic use case is used to define a jar or plugin version.

	<properties>
		<spring.version>3.1.2.RELEASE</spring.version>
	</properties>
 
	<dependencies>
 
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring.version}</version>
		</dependency>
 
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>
 
	</dependencies>

If you want to upgrade Spring to 3.1.5, just change the “spring.version” to 3.1.5, and all the dependencies will be affected.

Example 2

Another common use case is used to define a long file path.

<properties>
	<project.theme.name>default</project.theme.name>
	<project.resources.build.folder>
		${project.build.directory}/temp-resources/${project.theme.name}/
	</project.resources.build.folder>
</properties>
 
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-resources-plugin</artifactId>
	<version>2.5</version>
	<executions>
	  <execution>
	    <id>copy-resources</id>
	    <goals>
		<goal>copy-resources</goal>
	    </goals>
	    <configuration>
	    <outputDirectory>
                 ${project.resources.build.folder}
            </outputDirectory>
	    //...
Note
Furthermore, Maven comes with many useful project properties like project.build.directory}, project.build.directory}, make sure you check this Maven Properties Guide