如何在“mvn test”命令执行时添加Maven exec任务

5

我在我的pom文件中有以下的exec任务:

<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>${project.basedir}/src/test/javascript/EnvJasmine/bin/run_all_tests.sh</executable>
    </configuration>
  </plugin>
</plugins>

当我运行时,这个很好用。

mvn exec:exec

但是我希望它在执行时也能运行

mvn test

有人能在这里帮助我吗?

1个回答

7
明白了!您需要将 <phase> 添加到执行中。
<plugins>
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
      <execution>
        <id>Jasmine Tests</id>
        <phase>test</phase>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>${project.basedir}/src/test/javascript/EnvJasmine/bin/run_all_tests.sh</executable>
    </configuration>
  </plugin>
</plugins>

太棒了!


具体来说,在“test”阶段执行,您需要将<phase>test</phase>绑定项添加到<execution>元素中。 - Donal Fellows
1
嗨,刚看到你的帖子。 我已经使用exec maven插件来运行外部命令。这个命令运行一个服务器进行集成测试。 我的问题是maven在这个命令上卡住了,所以我无法运行测试。 我想知道你们中是否有人解决了这个问题。 - avi.elkharrat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接