Search code examples
mavenmodulemojomaven-module

Custom mojos with maven modules


I have a simple Maven multi-module project

Parent project
     ---Child project 1
     ---Child project 2 (depends on child project 1)

In the first project, I have a custom MOJO defined that I can call like this com.mycompany:child1artifactid:mojoname

Is it possible to call this same mojo from the child project since it is a dependency and bundled up as a jar for the second project? com.mycompany:child2artifactid:mojoname


Solution

  • No, it is not possible.

    When you invoke Maven with a plugin goal, it looks for a definition of this plugin in the project POM Maven is executed on. Since you are executing Maven on child2artifactid, and since this module does not declare mojoname, it won't work.

    Now, think about it, why would you want to do this? Invoking a plugin defined in another project is not really useful: either this project declares the plugin or you invoke Maven on the other project.

    Note however that when dealing with multi-module project, you often do not want to run Maven on child modules but simply on the parent project.