IntelliJ IDEA 14.1.0 Help

Extract Property

In Maven projects, while editing pom.xml, one needs to define a property and replace the occurrences of some value - artifact version, for example, - with this property.

For these purposes, IntelliJ IDEA provides the Extract Property refactoring.

Extract Property refactoring creates a new property definition in the specified pom.xml file, finds all the occurrences of the selected string in the hierarchy of pom.xml files, and replaces them with the above property in the format: ${<property_name>}

The Extract Property refactoring lets you move expressions and local declarations to properties.


In this example, artifact version is replaced with a property, which is declared in the same pom.xml file:
<artifactId>${submodule}</artifactId> <properties> <submodule>submodule</submodule> </properties>
In this example, artifact version in a pom.xml file is replaced with a property, which is declared in its parent pom.xml file:
<parent> <artifactId>HelloWorld</artifactId> <version>1.0</version> </parent> <artifactId>submodule<artifactId>
<artifactId>HelloWorld</artifactId> ... <modules> <module>${submodule}</module> </modules> ... <properties> <submodule>submodule</submodule> </properties>
<parent> <artifactId>HelloWorld</artifactId> <version>1.0</version> </parent> <artifactId>${submodule}</artifactId>

To extract a property in a pom.xml file

  1. Open the desired pom.xml file for editing, and place the caret somewhere inside the value you want to replace.
  2. Press Ctrl+Alt+V, or choose Refactor | Extract | Property on the context menu, or on the main menu. Note that selection will be automatically expanded up to the enclosing tags.
  3. In the Extract Property dialog box, do the following:
    • In the Name field, specify the name you want to assign to the new property. IntelliJ IDEA suggests a number of suitable names. You can select one from the drop-down list, or type the desired name manually.
    • In the Project drop-down list, select the project where the new property will be declared.
    Click OK.
  4. The subsequent workflow depends on the specific pom.xml file the refactoring has been invoked from.
    • The occurrence, for which the refactoring has been invoked, will be replaced silently. If the string occurs several times, the replace usage dialog will be displayed for these occurrences. You have to specify whether you want to replace each occurrence.
    • If the pom.xml is a parent file and the new property will be declared in it, IntelliJ IDEA replaces the values in the parent file silently, and displays the other occurrences in the Find tool window. You have to specify whether you want to replace each occurrence.
    • If the pom.xml is inherited from a parent file, IntelliJ IDEA replaces the occurrence in the child file silently. This change is not propagated to the parent pom.xml.

    In each case, IntelliJ IDEA adds new property declaration to the specified pom.xml file.

See Also

Language and Framework-Specific Guidelines:

Web Resources:

Last modified: 14 July 2015