简体   繁体   English

Maven 插件配置可以从父项目聚合到子项目吗

[英]Can a maven plugin configuration be aggregated from parent to child project

I have 3 maven projects, the parent, the middle, and the child project:我有 3 个 maven 项目,父项目、中间项目和子项目:

Parent-->Middle-->Child

Then I have 2 annotation processor dependencies.然后我有 2 个注释处理器依赖项。

The parent project defines maven-compiler-plugin as a managed plugin and configures annotation processor 1 on the annotationProcessorPath.父项目将 maven-compiler-plugin 定义为托管插件,并在 annotationProcessorPath 上配置注解处理器 1。 The middle project does likewise and configures annotation processor 2 on the annotationProcessorPath.中间项目也这样做,并在 annotationProcessorPath 上配置注释处理器 2。

Parent-->Middle-->Child
   |        |        
  AP1      AP2      

The compile of child project then fails because its missing annotation processor 1, because its configuration comes from middle project.然后子项目的编译失败,因为它缺少注释处理器 1,因为它的配置来自中间项目。 Easy answer is to simply add processor1 to the middle plugin configuration.简单的答案是简单地将 processor1 添加到中间插件配置中。

What I really want however is for child to inherit the managed configuration from both parent and middle and aggregate them.然而,我真正想要的是让孩子从父级和中间级继承托管配置并聚合它们。 Maybe it's just late at night but my gut tells me maven can handle this but I'm missing it.也许只是深夜,但我的直觉告诉我 maven 可以处理这个,但我很想念它。

This is from the parent pom:这是来自父pom:

<groupId>myproject</groupId>
<artifactId>base</artifactId>
<version>1.2-SNAPSHOT</version>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>myproject</groupId>
                            <artifactId>annotation1</artifactId>
                            <version>1.0</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

And from the middle pom:从中间的 pom 开始:

<parent>
    <groupId>myproject</groupId>
    <artifactId>base</artifactId>
    <version>1.2-SNAPSHOT</version>
 </parent>
 <artifactId>middle</artifactId>
 <version>1.1-SNAPSHOT</version>
 <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>myproject</groupId>
                            <artifactId>annotation2</artifactId>
                            <version>1.0</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

Can someone show me the technique for a different levels of the hierarchy (parent, middle) to add configuration to the plugin such that the child has the aggregate configuration from both有人可以向我展示不同层次结构(父级、中间级)的技术来向插件添加配置,以便子级拥有来自两者的聚合配置

It is as following:如下:

Root project - contains pluginManagement section with plugin X and its default configuration根项目 - 包含带有插件 X 及其默认配置的 pluginManagement 部分

The child project - contains plugin X section;子项目 - 包含插件 X 部分; any configuration added in this section is appended to the default configuration of the root (or overwrites - if the same arguments are redefined).本节中添加的任何配置都附加到根的默认配置(或覆盖 - 如果重新定义相同的参数)。

In your case the root should contain pluginManagement with annotation1;在您的情况下,应包含带有 annotation1 的 pluginManagement; the middle should contain plugin with annotation2 (this will be added to the default annotaion1);中间应该包含带有 annotation2 的插件(这将被添加到默认的 annotaion1); the child will inherit from the middle the plugin configuration with both annotations.孩子将从中间继承带有两个注释的插件配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM