在Maven安装后运行任务 [英] Running a task post maven install

查看:78
本文介绍了在Maven安装后运行任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在maven安装阶段之后运行一个简单的exec命令.实现这一目标的最简单方法是什么? (不添加新插件)

I want to run a simple exec command post maven install phase. What is the simplest way possible to achieve this? (without adding new plugins)

推荐答案

如果要在正常构建生命周期中运行此命令,除了将exec目标绑定到install阶段外,没有其他方法:

If you want to run this command as part of the normal build lifecycle, there is no other way than binding the exec goal on the install phase:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.1.1</version>
      <executions>
        <execution>
          <id>my-exec</id>
          <phase>install</phase>
          <goals>
            <goal>exec</goal>
          </goals>
          <inherited>false</inherited>
        </execution>
      </executions>
      <configuration>
        <executable>COMMAND</executable>
      </configuration>
    </plugin>
  </plugins>
</build>

我使用上面的配置(使用ls作为"COMMAND")对一个新创建的maven项目进行了简单测试,并运行mvn install会产生以下输出:

I did a simple test using the configuration above (using ls as "COMMAND") with a freshly created maven project and running mvn install produces the following output:


$ mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-exec-testcase
[INFO]    task-segment: [install]
[INFO] ------------------------------------------------------------------------
...
[INFO] [install:install {execution: default-install}]
[INFO] Installing /home/pascal/Projects/maven-exec-testcase/target/maven-exec-testcase-1.0-SNAPSHOT.jar to /home/pascal/.m2/repository/com/mycompany/app/maven-exec-testcase/1.0-SNAPSHOT/maven-exec-testcase-1.0-SNAPSHOT.jar
[INFO] [exec:exec {execution: my-exec}]
[INFO] pom.xml
[INFO] src
[INFO] target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12 seconds
[INFO] Finished at: Tue Jan 05 19:26:04 CET 2010
[INFO] Final Memory: 11M/75M
[INFO] ------------------------------------------------------------------------

正如我们所看到的,该命令在install阶段的末尾执行(在将工件复制到本地存储库之后).

As we can see, the command is executed at the end of the install phase (after the copy of the artifact to the local repository).

如果您确实不想将代码段添加到pom中,则必须按照whaley的建议,在命令行上的install之后显式调用exec:exec.

And if you really don't want to add the snippet to your pom, then you'll have to explicitly call exec:exec after install on the command line as suggested by whaley.

这篇关于在Maven安装后运行任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆