Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine many Maven goals within a single one

Tags:

java

maven

Until now, I'm using the command mvn clean compile hibernate3:hbm2java to launch my program. Is there any way to combine those three goals within a single one, e.g. mvn run or mvn myapp:run?

like image 581
sp00m Avatar asked Oct 10 '12 12:10

sp00m


People also ask

Are Maven goals tied to phases?

In Maven the "verbs" are goals packaged in Maven plugins which are tied to a phases in a build lifecycle. A Maven lifecycle consists of a sequence of named phases: prepare-resources, compile, package, and install among other. There is phase that captures compilation and a phase that captures packaging.

How many Maven goals are there?

There are three built-in lifecycles: default: the main lifecycle, as it's responsible for project deployment. clean: to clean the project and remove all files generated by the previous build.

What are the 3 build lifecycle of Maven?

There are three built-in build lifecycles: default, clean and site. The default lifecycle handles your project deployment, the clean lifecycle handles project cleaning, while the site lifecycle handles the creation of your project's web site.

What should I write in goals when Maven builds?

From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. In the list that opens, select Run Maven Goal. In the Select Maven Goal dialog, specify a project and a goal that you want to execute before launching the project.


1 Answers

Another solution that differs completely from my other answer would be to use the exec-maven-plugin with the goal exec:exec.

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <configuration>
                <executable>mvn</executable>
                <arguments>
                    <argument>clean</argument>
                    <argument>compile</argument>
                    <argument>hibernate3:hbm2java</argument>
                </arguments>
            </configuration>
        </plugin>
    </plugins>
</build>

And then you just run it like this:

mvn exec:exec

By doing it this way you are not changing any of the other plugins and it is not bound to any phases either.

like image 96
maba Avatar answered Sep 18 '22 11:09

maba