4

是否可以以某种方式并行运行多个 exec-maven-plugin 执行?

我们希望为 DAL 集成测试部署不同的数据库类型,虽然显然可以按顺序执行此操作,但这会浪费大量时间。

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>first-dbtype-deployment</id>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.example.DeployDBTypeOne</mainClass>
                    </configuration>
                </execution>
                <execution>
                    <id>second-dbtype-deployment</id>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>com.example.DeployDBTypeTwo</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
  </build>

实际部署的相应配置当然更复杂,但我认为这与所涉及的特定问题无关。

4

2 回答 2

1

使用两个模块设置项目:

  1. 模块 1 - 用于插件 first-dbtype-deployment 模块
  2. 对于插件 second-dbtype-deployment 并且不要在这些之间创建依赖关系,然后使用多个线程执行父项目:

示例: mvn -T 4 clean install # 使用 4 个线程构建 https://cwiki.apache.org/confluence/display/MAVEN/Parallel+builds+in+Maven+3

于 2019-05-09T20:46:12.250 回答
0

您可以使用在后台启动 Java 程序的 shellscript。这个 shellscript 看起来像:

#!/bin/bash
echo Starting dbtype-deployment $* on the background
java $* >/dev/null 2>&1 &

在您的 pom.xml 中,您可以使用 com.example.DeployDBTypeTwo 作为参数。

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2.1</version>
  <executions>
   <execution>
      <id>dbtype-deployment-x</id>
      <phase>integration-test</phase>
      <goals>
        <goal>exec</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <executable>startjava.sh</executable>
    <workingDirectory>${project.build.directory}/youKnowBest</workingDirectory>
    <arguments><argument>com.example.DeployDBTypeTwo</argument></arguments>
  </configuration>
</plugin>
于 2015-01-21T09:48:34.487 回答