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
Combine many Maven goals within a single one
提问by sp00m
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
?
到目前为止,我正在使用该命令mvn clean compile hibernate3:hbm2java
来启动我的程序。有没有办法将这三个目标结合在一个单一的目标中,例如mvn run
或mvn myapp:run
?
回答by maba
Another solution that differs completely from my other answer would be to use the exec-maven-plugin
with 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 hbm2java
goal binds to the generate-sources
phase 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-plugin
and the hibernate3-maven-plugin
in your pom.xml
you will have it all in one command.
无论如何,如果你在你的中添加maven-clean-plugin
和hibernate3-maven-plugin
,pom.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-plugin
to be run after compile
then just set the goal to compile
since 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>