IntelliJ IDEA 2018.2 Help

Maven refactorings

IntelliJ IDEA lets you use several extract refactorings while you work in your POM. For example, you can extract a dependency definition into a parent POM if you have a multi-module project. You can also extract a repeatable content of dependencies into a property to eliminate duplicates.

Extract managed dependency

Let's say you have a multi-module project and in one of sub projects you have defined several dependencies that can be used by other sub projects.

You can use Extract managed dependency refactoring to extract such dependency into a parent POM under dependencyManagement.

  1. In your POM, select the dependency you want to extract.

    maven depen extraction

  2. Press Ctrl+Alt+M or select Refactor | Extract | Extract Managed Dependency.

  3. IntelliJ IDEA extracts the selected dependency into a parent POM, automatically creating a dependencyManagement section and a full dependency definition.

    maven depen extract parent pom
    Use gutter icons to see a pop-up with dependency descriptions or to navigate between parent and sub projects' dependencies.

Extract property

Let's say you have a bunch of dependencies that have the same version.

You can use the Extract Property refactoring to extract such property into the properties section to manage it in one place.

  1. In your POM, select an item (in our case version) you want to extract.

    maven extract property

  2. Press Ctrl+Alt+V or select Refactor | Extract | Property.

  3. In the dialog that opens, specify a name of the property and name of the POM, click OK .

  4. IntelliJ IDEA creates a properties section with a new declaration and replaces the content of the selected dependency.

    maven extract propery result

  5. If IntelliJ IDEA encounters more than one occurrence, it displays them in the Find tool window where you can manage their replacement.

    maven find occurrences
    Click Replace All to replace all of the dependencies' versions.
    maven extract property result pom

Last modified: 25 October 2018

See Also