【问题标题】:Executing cargo:run from a maven profile执行货物:从 Maven 配置文件运行
【发布时间】:2016-04-07 02:55:44
【问题描述】:

我正在尝试编写一个 maven profile,它将运行 cargo:run goal 并将启动一个容器并等待用户按 CTRL + C 停止。但是,当我运行mvn clean install -PstartApplication 时,该命令无需等待即可成功完成。我错过了什么?

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

【问题讨论】:

    标签: maven maven-2 maven-cargo


    【解决方案1】:

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

    在这种特定情况下,Cargo 插件还在 Maven configuration 部分中的 provides 另一个 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-06
      • 1970-01-01
      • 2016-07-18
      • 2016-12-12
      • 2018-03-07
      • 2020-04-04
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多