【问题标题】:Is it possible to single out and run a specific goal bound to a maven phase?是否可以挑出并运行绑定到 Maven 阶段的特定目标?
【发布时间】:2011-01-16 04:17:19
【问题描述】:

更新为(希望)澄清:如果将目标定义为在给定阶段运行,是否可以在不运行所有阶段的情况下运行单个目标。换句话说,是否可以运行antrun:run 目标(定义为下面安装阶段的一部分)而无需获取依赖项、生成资源、编译、测试、打包等?

我在package 阶段使用antrun 插件创建一个zip 文件,并在install 阶段删除和复制一些文件。我了解如何运行单个 Maven 插件目标,例如:mvn antrun:run。但是,有没有办法运行特定的执行目标? mvn antrun:run:execution-id 或 mvn phase:antrun:run 之类的?

基本上,如果我可以告诉 maven 除了在部署阶段运行下面定义的 ant 任务之外什么都不做,我会很好。必须等待 maven 完成所有阶段以检查部署阶段中的 ant 任务是否正常工作,这有点乏味。

<executions>
  <!-- create zip file -->
  <execution>
    <id>create-zip</id>
    <phase>package</phase>
    <configuration>
      <tasks>
    ...create zip...
      </tasks>
    </configuration>
    <goals>
      <goal>run</goal>
    </goals>
      </execution>
  <!-- do some other stuff  -->
  <execution>
    <id>copy-files</id>
    <phase>install</phase>
    <configuration>
      <tasks>
    ...delete some files, copy some files ...
      </tasks>
    </configuration>
    <goals>
      <goal>run</goal>
    </goals>
      </execution>
    </executions>

【问题讨论】:

    标签: maven-2 ant


    【解决方案1】:

    换句话说,是否可以在不获取依赖项、生成资源、编译、测试、打包等的情况下运行 antrun:run 目标(定义为下面安装阶段的一部分)?

    不,不是。虽然您可以配置一个插件(在&lt;plugin&gt; 元素下使用&lt;configuration&gt; 部分)并在命令行上调用,但您不能调用特定的执行ID(因此&lt;configuration&gt; 特定于&lt;execution&gt;) .

    在您的情况下,唯一的解决方案是在配置文件中声明 antrun 插件,比如my-profile,复制以下配置部分以在此配置文件中配置插件:

    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.3</version>
      <configuration>
        <tasks>
          ... delete some files, copy some files ...
        </tasks>
      </configuration>
    </plugin>
    

    并使用正确的活动配置文件进行呼叫:

    mvn antrun:run -Pmy-profile
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        【解决方案3】:

        例如:

        当你用 maven 运行 jboss 时,你看不到 jboss 控制台输出,但我需要它显示,所以我写了一个 java 文件,读取 server.log(服务器控制台输出)为它会更改以显示更改,因此看起来 jboss 控制台实际上正在显示(有点 hack-ish 但可以正常工作)。所以我来回答你的问题,在预集成测试期间,我执行了一个 java 目标,它启动了我的 java 程序。这里是如何,当然使用执行插件:

        <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>console-start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <mainClass>org.eclipse.console.Main</mainClass>
                        </configuration>
                    </plugin>
        

        您只需运行安装,它会在预集成测试期间执行,但是如果您只想执行 java 之类的东西,请使用执行插件。对不起,如果答案不合适,我没有耐心详细阅读您的问题,我的工作时间结束了..干杯

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-03-29
          • 2012-01-26
          • 2019-01-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多