在 children 中执行 maven 插件,而不是在 grandchildren 或 parent 中执行

Execute maven plugin in children, not grandchildren or parent

我有一个 maven Mojo 插件,我只想在 child pom 中执行,而不是在当前 pom 或 grandchildren pom 中执行。我的插件 运行s 在编译时本质上是读取文件,对于我的用例,如果它 运行s 在 child pom 中,它对 运行 在 grandchildren poms.

例如,我有一个由 parent pom 文件 ParentFile 调用的 maven Mojo 插件。这个 pom 文件是在其他存储库中继承的,我没有 的写入权限。在这些存储库中,有一个带有 pom 文件 ChildFile 的根模块,其 parent 是 ParentFile。存储库中还有其他子模块包含 pom 文件 (GrandchildrenFiles),其 parent 是 ChildFile.

我想从 ChildFile 执行我的 Mojo 插件,而不是从 GrandchildrenFiles 或 ParentFile。有没有办法让我在不对包含 ChildFile 和 GrandchildrenFiles 的存储库进行写访问的情况下执行此操作?

你可能无法阻止你的插件被执行,但你可以检查,作为插件的第一步,如果你的父级是你期望的父级。为此,您可以使用 project.getParent().

如果没有,你就跳过剩下的执行。