首页 > 解决方案 > 是否可以在父 pom 中指定 pluginManagement?

问题描述

我正在尝试为多模块项目设置 Maven 插件管理。我想使用pluginManagement没有继承的部分(指定不在父 pom 中的插件版本)。我的项目结构看起来像这样

base_project
   -- pom.xml
   -- project-bom
        -- pom.xml
   -- project-a
        -- pom.xml

在根 pom.xml 我只有两个模块:

<modules>
    <module>project-bom</module>
    <module>project-a</module>
</modules>

在 project-bom pom.xml 中,我指定了我想要使用的依赖项和插件版本的部分dependencyManagementpluginManagement

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.some</groupId>
            <artifactId>dependency</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.some</groupId>
                <artifactId>plugin</artifactId>
                <version>1.0.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

在 project-a pom.xml 中,我导入 project-bom pom 并使用依赖项和插件:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.project</groupId>
            <artifactId>project-bom</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.some</groupId>
        <artifactId>dependency</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.some</groupId>
            <artifactId>plugin</artifactId>
        </plugin>
    </plugins>
</build>

我可以使用 project-bom 中指定的依赖版本,但它不适用于插件。它给了我以下警告:

[WARNING] Some problems were encountered while building the effective model for <...>
[WARNING] 'build.plugins.plugin.version' for <org.some:plugin> is missing. 

是否可以在父 pom 中指定 pluginManagement 并导入它?

标签: mavenmaven-3

解决方案


目前这是不可能的。在 Maven项目中有一个open ticket可以添加此功能。


推荐阅读