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.
Examples
To extract a property in a pom.xml file
- Open the desired
pom.xml
file for editing, and place the caret somewhere inside the value you want to replace. - Press Ctrl+Alt+V, or choose on the context menu, or on the main menu. Note that selection will be automatically expanded up to the enclosing tags.
- 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.
- 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 parentpom.xml
.
In each case, IntelliJ IDEA adds new property declaration to the specified
pom.xml
file.