是否可以挑出并运行绑定到 Maven 阶段的特定目标? [英] Is it possible to single out and run a specific goal bound to a maven phase?
问题描述
更新为(希望)澄清:如果将目标定义为在给定阶段运行,是否可以运行单个目标而不运行所有阶段.换句话说,是否可以在不获取依赖项、生成资源、编译、测试、打包等的情况下运行 antrun:run
目标(定义为下面安装阶段的一部分)?
Updated to (hopefully) clarify: If a goal is defined to run during a given phase, is it possible to run the individual goal without running thru all phases. In other words would it be possible to run the antrun:run
goal (which is defined as part of the install phase below) without getting dependencies, generate-resources, compiling, testing, package, etc?
我正在使用 antrun 插件在 package
阶段创建一个 zip 文件,并在 install
阶段删除和复制一些文件.我了解如何运行单个 Maven 插件目标,例如:mvn antrun:run
.但是,有没有办法运行特定执行的目标?类似于 mvn antrun:run:execution-id
或 mvn phase:antrun:run
?
I'm using the antrun plugin to create a zip file during the package
phase and to delete and copy some files during the install
phase. I understand how to run single maven plugin goals, for example: mvn antrun:run
. However, is there a way to run a specific execution's goal? Something like mvn antrun:run:execution-id
, or mvn phase:antrun:run
?
基本上,例如,如果我可以告诉 maven 除了在部署阶段运行下面定义的 ant 任务之外什么都不做,我会很好.必须等待 maven 完成所有阶段才能检查部署阶段的 ant 任务是否正常工作,这有点乏味.
Basically, I'd be nice if I can tell maven to do nothing else but run the ant tasks defined below inside the deploy phase, for example. It's kind of tedious having to wait for maven to go thru all the phases just to check if the ant tasks in the deploy phase are working correctly.
<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>
推荐答案
换句话说,是否可以在不获取依赖项、生成资源、编译、测试、打包等的情况下运行 antrun:run 目标(定义为下面安装阶段的一部分)?
In other words would it be possible to run the antrun:run goal (which is defined as part of the install phase below) without getting dependencies, generate-resources, compiling, testing, package, etc?
不,不是.虽然您可以配置插件(使用
元素下的
部分)并在命令行上调用,但您不能调用特定的执行 ID(以及特定于
的
).
No it's not. While you can configure a plugin (with a <configuration>
section under the <plugin>
element) and call in on the command line, you can't invoke a specific executionid (and consequently the <configuration>
specific to an <execution>
).
在您的情况下,唯一的解决方案是在配置文件中声明 antrun 插件,例如 my-profile
,复制配置的以下部分以在此配置文件中配置插件:
The only solution in your case would be to declare the antrun plugin in a profile, let's say my-profile
, to duplicate the following part of the configuration to configure the plugin in this profile:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<configuration>
<tasks>
... delete some files, copy some files ...
</tasks>
</configuration>
</plugin>
并使用正确的活动配置文件呼叫:
and to call with the right active profile:
mvn antrun:run -Pmy-profile
这篇关于是否可以挑出并运行绑定到 Maven 阶段的特定目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!