Maven mojo插件,如何定义在此目标之前必须触发的阶段?

发布于 2024-09-27 19:35:22 字数 805 浏览 4 评论 0原文

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

通过执行元素(根据文档),我可以将我的目标附加到特定阶段,例如将其绑定到之后的阶段,所以在我的例子中,安装阶段......但这只是一种解决方法。

  <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>

简而言之,如果我只将我的目标放入构建部分并运行它,则之前不会运行包阶段。请帮忙

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻许诺言 2024-10-04 19:35:22

Maven Mojo插件,如何定义在此目标之前必须触发的阶段?

你不能。

我在 pom 定义的构建部分中有远程部署插件,我需要在部署远程目标之前触发包阶段,因为在我将其安全复制到远程服务器之前,战争已经创建了。< /p>

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

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

  <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] ------------------------------------------------------------------------
...

正如预期的那样,antrun 插件在 package 之后执行。

Maven Mojo plugin, how to define phases that must be triggered before this goal ?

You can't.

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.

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).

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>

And the output of 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] ------------------------------------------------------------------------
...

The antrun plugin is executed after package, as expected.

甩你一脸翔 2024-10-04 19:35:22

您可以尝试在 @Mojo 注释中使用 PREPARE_PACKAGE 阶段:

@Mojo(name = "myName", defaultPhase = LifecyclePhase.PREPARE_PACKAGE)

You can try use PREPARE_PACKAGE phase in your @Mojo annotation:

@Mojo(name = "myName", defaultPhase = LifecyclePhase.PREPARE_PACKAGE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文