Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a custom Maven goal without pom.xml

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.

like image 874
Sayid Avatar asked Apr 26 '16 09:04

Sayid


People also ask

What is Maven pom XML?

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.

How do I run a specific goal in Maven project?

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

What are the goals of a Maven plugin?

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:

How to set up a Maven project with xmltojson?

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.


1 Answers

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  { ... }
like image 144
Tunaki Avatar answered Oct 13 '22 21:10

Tunaki