VMS
VMS

Reputation: 403

Execute maven plugin in children, not grandchildren or parent

I have a maven Mojo plugin that I'd like to execute only in child pom, but not in the current pom or grandchildren poms. My plugin runs at compile time and essentially reads files, and for my use case if it runs in the child pom, it is redundant to run in grandchildren poms.

For example, I have a maven Mojo plugin that gets called by a parent pom file ParentFile. This pom file is inherited in other repositories, which I don't have write access to. In these repositories, there is a root module with a pom file ChildFile, whose parent is ParentFile. There are also other submodules in the repository that contain pom files (GrandchildrenFiles) whose parent is ChildFile.

I would like to execute my Mojo plugin from ChildFile, but not from GrandchildrenFiles or ParentFile. Is there a way for me to do this without write access to the repositories containing ChildFile and GrandchildrenFiles?

Upvotes: 1

Views: 163

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35785

You probably cannot stop your plugin from being executed, but you could check, as first step in your plugin, if your parent is the parent you expected. For that, you can use project.getParent().

If not, you just skip the rest of the execution.

Upvotes: 1

Related Questions