如何定义必须在此目标之前触发的阶段

如何定义必须在此目标之前触发的阶段

本文介绍了Maven mojo插件,如何定义必须在此目标之前触发的阶段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个deploy pojo插件(将战争部署到远程服务器).我在pom定义的build部分中有remote-deploy插件,我需要在部署-remote目标之前触发程序包阶段,因为在将其安全复制到远程服务器之前已经创建了战争.

hey,I have a deploy pojo plugin (deploying a war to a remote server). I have the remote-deploy plugin in the build section of pom definition, I need package phase to be triggered before deploy-remote goal, for it the war be already created before I secure-copy it to a remote server.

借助执行元素(根据文档),我可以将目标附加到特定阶段,例如将其绑定到之后的阶段,因此,在我的情况下,是安装阶段...但这只是一种解决方法. /p>

With the execution elements (according to a documentation), I can attach my goal to a particular phase, for instance bind it to the phase after, so in my case, install phase ...but that's just a workaround.

  <build>
    <plugins>
      <plugin>
        <groupId>sample.plugin</groupId>
        <artifactId>maven-hello-plugin</artifactId>
        <version>1.0-SNAPSHOT</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>sayhi</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

简而言之,如果我仅将目标放入构建部分并运行,则打包阶段不会运行.请帮助

simply put, if I place only my goal into the build section, and run it, package phase is not run before. Please help

推荐答案

你不能.

只需将其绑定到package阶段,默认情况下目标将绑定到package后将调用您的目标(因此战争将在那里).

Just bind it to the package phase, your goal will be called after the goals bounds to package by default (so the war will be there).

下面是一个示例,该示例使用配置如下的Maven AntRun插件来演示此行为:

Here is an example demonstrating this behavior with the Maven AntRun plugin configured like this:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
      <execution>
        <phase>package</phase>
        <configuration>
          <target>
            <echo message="Hi!!!!!"/>
          </target>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

mvn package的输出:


$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3934833 Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ Q3934833 ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.5:test (default-test) @ Q3934833 ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.1:war (default-war) @ Q3934833 ---
[INFO] Packaging webapp
[INFO] Assembling webapp [Q3934833] in [/home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/pascal/Projects/stackoverflow/Q3934833/src/main/webapp]
[INFO] Webapp assembled in [317 msecs]
[INFO] Building war: /home/pascal/Projects/stackoverflow/Q3934833/target/Q3934833.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- maven-antrun-plugin:1.6:run (default) @ Q3934833 ---
[INFO] Executing tasks

main:
     [echo] Hi!!!!!
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

按预期,在package之后执行antrun插件.

The antrun plugin is executed after package, as expected.

这篇关于Maven mojo插件,如何定义必须在此目标之前触发的阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:02