【问题标题】:Is it possible to run multiple maven-exec-plugin executions in parallel?是否可以并行运行多个 maven-exec-plugin 执行?
【发布时间】:2015-03-04 11:40:04
【问题描述】:

是否可以以某种方式并行运行多个 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>

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

【问题讨论】:

  • 您使用哪个 Maven 版本?你都尝试了些什么?你试过运行mvn -T 2.0...吗?
  • 用于并行运行/构建多个模块/项目。我不是在寻找那个。我需要的是在同一个模块/项目中并在同一阶段并行运行多个(java)可执行文件。

标签: maven maven-plugin exec-maven-plugin


【解决方案1】:

您可以使用在后台启动 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>

【讨论】:

    【解决方案2】:

    使用两个模块设置项目:

    1. 模块 1 - 用于插件 first-dbtype-deployment 模块
    2. 用于插件第二个数据库类型部署 并且不要在这些之间创建依赖关系 然后用多个线程执行父项目:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-12
      • 2012-03-13
      • 2017-05-06
      • 2014-04-23
      • 1970-01-01
      • 2019-12-30
      • 2012-03-03
      • 2011-07-03
      相关资源
      最近更新 更多