Run a custom Maven goal without pom.xml

2019-06-17 03:56发布

问题:

I have developed a Maven plugin. How to run custom Maven goal from a directory that does not contain a pom.xml?

E.g. mvn my.plugin:mygoal <- no pom.xml in this dir.

回答1:

You can set the requiresProject attribute of your MOJO to false:

Flags this Mojo to run inside of a project.

By default, it is true meaning that this MOJO requires a project (hence a POM). As such, you should have in your plugin:

@Mojo(requiresProject = false, ...)
public class MyMojo extends AbstractMojo  { ... }