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.
Maven pom.xml file POM is an acronym for Project Object Model. The pom.xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc. Maven reads the pom.xml file, then executes the goal.
To run a specific goal, without executing its entire phase (and the preceding phases) we can use the command: mvn <PLUGIN>:<GOAL> For example, to run integration-test goal from Failsafe plugin, we need to run: mvn failsafe:integration-test 6. Building a Maven Project
A Maven plugin is a group of goals. However, these goals aren't necessarily all bound to the same phase. For example, here's a simple configuration of the Maven Failsafe plugin which is responsible for running integration tests: As we can see, the Failsafe plugin has two main goals configured here:
You need to have either Apache maven installed in your local machine or integrated into your IDE to set up the project. We will develop a simple maven-plugin named xmltojson-maven-plugin. By convention, core Maven plugins provided by Maven are named as maven-<taskName>-plugin.
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 { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With