2016-01-03 52 views
0

我想写一个maven profile将运行cargo:rungoal,将启动一个容器,等待用户按CTRL + C停止运行。但是,当我运行mvn clean install -PstartApplication时,该命令成功完成,无需等待。我错过了什么?执行货物:从一个Maven轮廓

<profile> 
    <id>startApplication</id> 
    <build> 
     <plugins> 
     <plugin> 
      <groupId>org.codehaus.cargo</groupId> 
      <artifactId>cargo-maven2-plugin</artifactId> 
      <configuration> 
       <wait>true</wait> 
       <container> 
        <containerId>tomcat7x</containerId> 
        <type>installed</type> 
        <home>${catalina.home}</home> 
       </container> 
       <configuration> 
        <type>standalone</type> 
        <home>${project.basedir}/target/tomcat7x</home> 
       </configuration> 
       <deployables> 
        <deployable> 
        <properties> 
         <context>ROOT</context> 
        </properties> 
        <groupId>com.demo.web</groupId> 
        <artifactId>sample-web-app</artifactId> 
        <type>war</type> 
        </deployable> 
       </deployables> 
       <executions> 
        <execution> 
        <id>start-container</id> 
        <phase>pre-integration-test</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        </execution> 
       </executions> 
      </configuration> 
     </plugin> 
     </plugins> 
    </build> 
</profile> 

回答

1

检查插件配置:在您发布的代码executions元素是configuration元素,这是不正确的范围内,因此它会被Maven的被忽略。 (查看official documentation了解更多详情)。
executions部分应该在configuration部分之外(并且在相同的嵌套级别)。然后,他们还可以包含另一个configuration部分,该部分将是该特定包装execution所使用的配置,而以前是默认应用于所有列出的执行的更一般配置。

在这种特定的情况下,货物插件也provides Maven的configuration段内的进一步configuration元素,这使得事情有点混乱和误导性(不同的名称已选定,在我看来)。

因此,在你的情况,你应该搬出executions部分从configuration部分,如下:

<profile> 
    <id>startApplication</id> 
    <build> 
     <plugins> 
     <plugin> 
      <groupId>org.codehaus.cargo</groupId> 
      <artifactId>cargo-maven2-plugin</artifactId> 
      <configuration> 
       <wait>true</wait> 
       <container> 
        <containerId>tomcat7x</containerId> 
        <type>installed</type> 
        <home>${catalina.home}</home> 
       </container> 
       <configuration> 
        <type>standalone</type> 
        <home>${project.basedir}/target/tomcat7x</home> 
       </configuration> 
       <deployables> 
        <deployable> 
        <properties> 
         <context>ROOT</context> 
        </properties> 
        <groupId>com.demo.web</groupId> 
        <artifactId>sample-web-app</artifactId> 
        <type>war</type> 
        </deployable> 
       </deployables> 
      </configuration> 
      <executions> 
       <execution> 
       <id>start-container</id> 
       <phase>pre-integration-test</phase> 
       <goals> 
        <goal>run</goal> 
       </goals> 
       </execution> 
      </executions> 
     </plugin> 
     </plugins> 
    </build> 
</profile>