可以将 Maven 插件配置从 parent 聚合到 child 项目
Can a maven plugin configuration be aggregated from parent to child project
我有 3 个 maven 项目,parent,中间项目和 child 项目:
Parent-->Middle-->Child
然后我有 2 个注释处理器依赖项。
parent 项目将 maven-compiler-plugin 定义为托管插件,并在 annotationProcessorPath 上配置注释处理器 1。中间项目也这样做,并在 annotationProcessorPath 上配置注释处理器 2。
Parent-->Middle-->Child
| |
AP1 AP2
child 项目编译失败,因为它缺少注释处理器 1,因为它的配置来自中间项目。简单的答案是简单地将 processor1 添加到中间插件配置中。
然而,我真正想要的是 child 继承 来自 parent 和中间的托管配置并聚合它们。也许只是深夜,但我的直觉告诉我 maven 可以处理这个,但我想念它。
这是来自 parent 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>
从中间的 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>
有人可以向我展示不同级别层次结构(parent,中间)的技术,以便向插件添加配置,以便 child 具有来自两个 [=16] 的聚合配置=]
如下:
根项目 - 包含带有插件 X 及其默认配置的 pluginManagement 部分
子项目 - 包含插件 X 部分;本节中添加的任何配置都会附加到根的默认配置(或覆盖 - 如果重新定义了相同的参数)。
在你的例子中,root 应该包含带有 annotation1 的 pluginManagement; middle 应该包含带有 annotation2 的插件(这将被添加到默认的 annotaion1); child 将从 middle 继承带有两个注释的插件配置。
我有 3 个 maven 项目,parent,中间项目和 child 项目:
Parent-->Middle-->Child
然后我有 2 个注释处理器依赖项。
parent 项目将 maven-compiler-plugin 定义为托管插件,并在 annotationProcessorPath 上配置注释处理器 1。中间项目也这样做,并在 annotationProcessorPath 上配置注释处理器 2。
Parent-->Middle-->Child
| |
AP1 AP2
child 项目编译失败,因为它缺少注释处理器 1,因为它的配置来自中间项目。简单的答案是简单地将 processor1 添加到中间插件配置中。
然而,我真正想要的是 child 继承 来自 parent 和中间的托管配置并聚合它们。也许只是深夜,但我的直觉告诉我 maven 可以处理这个,但我想念它。
这是来自 parent 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>
从中间的 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>
有人可以向我展示不同级别层次结构(parent,中间)的技术,以便向插件添加配置,以便 child 具有来自两个 [=16] 的聚合配置=]
如下:
根项目 - 包含带有插件 X 及其默认配置的 pluginManagement 部分
子项目 - 包含插件 X 部分;本节中添加的任何配置都会附加到根的默认配置(或覆盖 - 如果重新定义了相同的参数)。
在你的例子中,root 应该包含带有 annotation1 的 pluginManagement; middle 应该包含带有 annotation2 的插件(这将被添加到默认的 annotaion1); child 将从 middle 继承带有两个注释的插件配置。