2012-10-10 23 views
13

到现在为止,我正在使用命令mvn clean compile hibernate3:hbm2java来启动我的程序。有什么方法可以将这三个目标合并为一个目标,例如mvn runmvn myapp:run在单个目标中合并许多Maven目标

回答

16

另一种解决方案是不同完全从我的其他答案将是使用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> 

然后你只要运行它是这样的:

mvn exec:exec 

通过做这种方式,你不改变任何其他插件,它是没有绑定到任何阶段无论是。

+0

我希望拥有相同的内容,而且我真的真的想要放回一个makefile文件。但我认为......应该有一个maven解决方案..所以你说的确是它不在那里?作为,执行,如果我从名称得到它的权利,并有将“执行”的事实!..所以不是很容易管理步骤,依赖和返回代码..是否真的如此的maven?我不能连锁目标?我的意思是有点控制? – mariotti

+0

刚刚搜索一遍,发现这个2005年的文档:http://docs.codehaus.org/display/MAVEN/Multiple+Goal+Declaration – mariotti

+0

正是我寻找的解决方案! 注意:版本1.5.0在Windows上是有问题的。请参阅 - https://github.com/mojohaus/exec-maven-plugin/issues/42因此,如果您想在此使用,请避免这种情况。当它们释放一个版本时,使用以前的版本1.4.0或更新版本> 1.5.0 – codewing

5

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

通常,您不必清理项目,就可以运行增量构建。

无论如何,如果您在pom.xml中添加了maven-clean-pluginhibernate3-maven-plugin,您将可以在一个命令中使用它。

<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> 

如果你想hibernate3-maven-plugincompile后运行,那么就在目标设定为compile因为它会默认后阶段始终运行。

所以要运行一个命令所有的目标只是运行:

mvn compile 

如果你因任何原因不希望清理,然后只需键入:

mvn compile -Dclean.skip 
+0

如果你不希望它总是运行'hbm2java',那么将其放置在[profile](http://www.sonatype.com/books/mvnref- book/reference/profiles-sect-what.html),即'mvn compile -Phbm' – noahlz