【问题标题】:Properly binding maven exec plugin to test phase将 maven exec 插件正确绑定到测试阶段
【发布时间】:2013-10-05 20:32:47
【问题描述】:

在一个 Maven 项目中,我使用 maven-exec-plugin 来启动我的 Grunt 测试。它是这样的:

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
          <execution>
            <phase>test</phase>
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <executable>cmd</executable>
          <workingDirectory>${project.basedir}/src/main/webapp</workingDirectory>
          <arguments>
            <argument>/C</argument>
            <argument>grunt --no-color test</argument>
          </arguments>
        </configuration>  
      </plugin>
    </plugins>
  </build>

这样我就可以运行 mvn test 并且我的 grunt test 任务将被执行:如果测试通过,maven 构建通过,如果测试失败,maven 构建失败。当一些测试失败时,我有以下输出:

  .............................................  1 failing
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 3.496s
  [INFO] Finished at: ** ** ** **:**:** CEST ****
  [INFO] Final Memory: *M/*M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default) on project *****: Command execution failed. Process exited with an error: 6 (Exit value: 6) -> [Help 1]

我想知道是否有可能为失败的测试提供“通常”的 Maven 输出。类似:Build failure, there are failing tests

谢谢

【问题讨论】:

    标签: maven testing gruntjs mocha.js


    【解决方案1】:

    不容易。构建失败消息显示失败插件抛出的异常;在exec-maven-plugin 的情况下,这只会是退出代码的报告。它不会考虑命令行为中的任何其他内容。

    如果你下定决心,你可以重写或扩展exec-maven-plugin,或者在 Groovy 中编写类似的东西来抛出带有更具体消息的异常。

    (存在grunt-maven-plugin,但它也委托给exec-maven-plugin。)

    【讨论】:

    • 是的,这就是我所担心的。感谢您指向grunt-maven-plugin 的指针,尽管我更喜欢使用exec-maven-plugin
    猜你喜欢
    • 2011-04-28
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2017-12-12
    相关资源
    最近更新 更多