【问题标题】:How to call maven-antrun-plugin target without attach execution to a maven phase ?如何在不将执行附加到 maven 阶段的情况下调用 maven-antrun-plugin 目标?
【发布时间】:2012-05-20 01:43:30
【问题描述】:

我将 maven-antrun-plugin 用于我的项目的初始化配置文件。但是我只需要初始化一次配置文件,当我第一次开始初始化我的开发环境时,而不是每次我启动 jetty:run 时。

例如,如果我将阶段附加到进程资源,则每次启动码头时,我的配置文件都会重置。

所以我这样配置antrun:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
        <goals>
            <goal>run</goal>
        </goals>
        <configuration>
            <target name="init_config_files">
                <!-- init files -->
            </target>
        </configuration>
        </execution>
    </executions>
</plugin>

如果我启动 mvn antrun:run,它只会返回这个错误:“[INFO] No ant target defined - SKIPPED”。如果我指定目标:“mvn antrun:run -Dtarget=init_config_files”,也是一样的。

【问题讨论】:

    标签: maven maven-antrun-plugin


    【解决方案1】:

    目前为止我找到的最佳解决方案:

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>go-live</id>
                        <configuration>
                            <target>
                                <!-- go live! -->
                                <exec executable="${basedir}/deploy2server.sh" failonerror="true" dir="${basedir}">
                                    <arg value="deploy" />
                                    <arg value="${deploy.to.server}" />
                                    <arg value="${jetty.port.live}" />
                                </exec>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    然后运行:

     mvn antrun:run@go-live
    

    此解决方案避免了目标被意外运行,即。它不仅可以通过键入“mvn antrun:run”来运行,而且它也不会在常规 maven 运行期间运行。在所有模块(包括针对最终分发包完成的集成)都已成功执行后,我将其用于我的 jenkins 实例中的 qa 自动部署。

    【讨论】:

    • 非常好的解决方案。使用此方法,您可以执行多个执行,并且可以选择其中一个。
    • 有史以来最好的答案!在你的帮助下,我现在可以运行单独的执行:D 谢谢
    【解决方案2】:

    我刚遇到同样的问题,终于搞明白了:如果你只想运行一次ant任务,你可以这样设置插件:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <configuration>
            <target name="init_config_files">
                <!-- init files -->
            </target>
        </configuration>
    </plugin>
    

    并使用mvn antrun:run 来执行它。这样,蚂蚁的东西就不会绑定到任何阶段。

    【讨论】:

      【解决方案3】:

      试试这个:

              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-antrun-plugin</artifactId>
                  <version>1.7</version>
                  <executions>
                      <execution>
                          <id>default-cli</id>
                          <configuration>
                              <target>
                                  <property name="compile_classpath" refid="maven.compile.classpath" />
                                  <echo message="compile classpath: ${compile_classpath}" />
                              </target>
                          </configuration>
                          <goals>
                              <goal>run</goal>
                          </goals>
                      </execution>
                  </executions>
              </plugin>
      

      然后运行:

       mvn antrun:run
      

      【讨论】:

        【解决方案4】:

        如果您需要在特殊条件下运行构建的某些部分(例如一次),您可以将这些部分放入 Maven profile 然后调用 Maven 指定配置文件名称,例如mvn -p init_config_files package

        【讨论】:

        • 我已经将这个解决方案用于另一个插件,我只是被我的想法阻止了:“为什么 antrun 绝对想要附加到一个阶段?” :) Thx
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-09
        • 1970-01-01
        • 2021-07-16
        • 1970-01-01
        • 2019-09-06
        • 1970-01-01
        • 2012-05-30
        相关资源
        最近更新 更多