java 将许多 Maven 目标组合在一个单一的目标中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12819773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:20:52  来源:igfitidea点击:

Combine many Maven goals within a single one

javamaven

提问by sp00m

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

到目前为止,我正在使用该命令mvn clean compile hibernate3:hbm2java来启动我的程序。有没有办法将这三个目标结合在一个单一的目标中,例如mvn runmvn myapp:run

回答by maba

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

另一个与我的其他答案完全不同的解决方案是将exec-maven-plugin与目标一起使用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.

通过这样做,您不会更改任何其他插件,也不会绑定到任何阶段。

回答by maba

According to the Hibernate3 Maven Pluginsite the hbm2javagoal binds to the generate-sourcesphase by default.

根据Hibernate3 Maven Plugin站点,hbm2java目标generate-sources默认绑定到阶段。

And normally you won't have to clean the project, you run incremental builds.

通常您不必清理项目,而是运行增量构建。

Anyway if you add the maven-clean-pluginand the hibernate3-maven-pluginin your pom.xmlyou will have it all in one command.

无论如何,如果你在你的中添加maven-clean-pluginhibernate3-maven-pluginpom.xml你将在一个命令中拥有它。

<build>
    <plugins>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>auto-clean</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>hbm2java</id>
                    <goals>
                        <goal>hbm2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

If you want the hibernate3-maven-pluginto be run after compilethen just set the goal to compilesince it will always run after default phases.

如果您希望在hibernate3-maven-plugin之后运行,compile则只需将目标设置为,compile因为它将始终在默认阶段之后运行。

So to run all your goals with one command just run:

因此,要使用一个命令运行所有目标,只需运行:

mvn compile

And if you for any reason don't want to clean then just type:

如果您出于任何原因不想清洁,则只需键入:

mvn compile -Dclean.skip

回答by Igor Kanshyn

You can also define a default goalfor Maven build. Then your command line call will look like this

您还可以为 Maven 构建定义一个默认目标。然后您的命令行调用将如下所示

mvn

Defining default goal

定义默认目标

Add this following lines to your pom.xml:

将以下行添加到您的 pom.xml 中:

<build>
    <defaultGoal>clean compile hibernate3:hbm2java</defaultGoal>
</build>