# Maven 重构

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/idea/llms.txt).

IntelliJ IDEA 允许您在使用 POM 时进行几种提取重构。 例如，如果您有一个多模块项目，您可以将依赖定义提取到父 POM 中。 您还可以将依赖项的重复内容提取到属性中以消除重复。

## 提取管理的依赖项

假设您有一个多模块项目，并且在其中一个子项目中定义了几个可以被其他子项目使用的依赖。

您可以使用  提取托管依赖项 重构将此类依赖项提取到父 POM 中  `dependencyManagement` 。

Procedure:

1. 在您的 POM 中，选择要提取的依赖项。

![依赖项示例的 POM](https://resources.jetbrains.com.cn/help/img/idea/2026.3/maven_depen_extract.png)

2. 按 `Ctrl+Alt+M` (Windows), `⌘ ⌥ M` (macOS), `⌘ ⌥ M` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ M` (macOS System Shortcuts), `Ctrl+Alt+M` (XWin), `Ctrl+Alt+M` (GNOME), `Ctrl+Alt+M` (KDE), `Ctrl+Alt+M` (Emacs), `Ctrl+Alt+M` (Sublime Text), `⌘ ⌥ M` (Sublime Text (macOS)), `Ctrl+R, M` (Visual Studio), `⌘ R, M` (Visual Studio (macOS)), `Alt+Shift+M` (NetBeans), `Alt+Shift+M` (Eclipse), `⌘ ⌥ M` (Eclipse (macOS)) 或选择  `重构 | 提取 | 提取托管依赖项` 。

3. IntelliJ IDEA 将所选的依赖项提取到父 POM 中，自动创建一个  `dependencyManagement`  部分和完整的依赖项定义。

![提取依赖项的父 POM](https://resources.jetbrains.com.cn/help/img/idea/2026.3/parent_pom_with_extraction.png) 使用标记图标查看依赖关系描述弹出窗口或在父项目和子项目的依赖关系之间导航。

## 引入属性

假设您有一堆依赖项，它们拥有相同的  `版本` 。

您可以使用   引入属性  重构在  `properties` 部分引入一个属性，以便在一个地方进行管理。

Procedure:

1. 在您的 POM 中，选择您想要提取的项目（在本例中为  `版本` ）。

![具有相同版本的依赖项的 POM](https://resources.jetbrains.com.cn/help/img/idea/2026.3/maven_extract_property.png)

2. 按 `Ctrl+Alt+V` (Windows), `⌘ ⌥ V` (macOS), `⌘ ⌥ V` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ V` (macOS System Shortcuts), `Ctrl+Alt+V` (XWin), `Ctrl+Alt+V` (GNOME), `Alt+Shift+V` (KDE), `Ctrl+Alt+V` (Emacs), `Ctrl+Alt+V` (Sublime Text), `Ctrl+Alt+V` (Sublime Text (macOS)), `Ctrl+R, V` (Visual Studio), `⌘ R, V` (Visual Studio (macOS)), `Alt+Shift+V` (NetBeans), `Alt+Shift+L` (Eclipse), `⌘ ⌥ L` (Eclipse (macOS)) 或选择  `重构 | 属性` 。

3. 在 [引入属性](#introduce-property-dialog) 对话框中，指定属性名称和 POM 名称，然后点击   OK  。

![引入属性对话框](https://resources.jetbrains.com.cn/help/img/idea/2026.3/maven_introduce_property.png)

4. IntelliJ IDEA 会创建一个  `properties` 部分，其中包含一个新的声明，并替换所选依赖项的内容。

![声明属性的 POM](https://resources.jetbrains.com.cn/help/img/idea/2026.3/maven_extract_property_result.png)

5. 如果 IntelliJ IDEA 遇到多次出现的情况，它会在 [Find](find-tool-window.html) 工具窗口中显示这些情况，您可以在此管理它们的替换。

![“查找”工具窗口](https://resources.jetbrains.com.cn/help/img/idea/2026.3/maven_find_occurrences.png) 点击   全部替换   以替换所有依赖项的版本。

![更改版本的 POM](https://resources.jetbrains.com.cn/help/img/idea/2026.3/maven_extract_property_result_pom.png)

## 引入属性对话框

请使用此对话框指定   引入属性   重构的选项。

|  条目  |  描述  |
| --- | --- |
|  名称  |  在此字段中，指定您要分配给新属性的名称。 您可以手动输入该名称或者选择 IntelliJ IDEA 建议的一个值。  |
|  项目  |  选择您的新属性将被声明的  `pom.xml` 。  |

## See also

### 操作指南

[Maven dependencies in a multi-module project](work-with-maven-dependencies.html)

