如何将maven antrun插件绑定到clean阶段
我刚刚将一个 ant 项目翻译成 Maven,但是由于 Maven 并不真正处理部署,所以我在构建中引入了一些 antrun。但是,当我尝试执行它时,插件会跳过我的任务。例如,当我运行 mvn clean antrun:run 时,我收到以下消息:未定义 ant 目标 - 已跳过。第二阶段也发生了同样的情况,我试图覆盖部署阶段以进行实际部署,而不是上传到存储库。
请在下面找到我的 pom.xml 的摘录(类型:pom):
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>clean</id>
<configuration>
<task>
<echo>Cleaning deployed website</echo>
</task>
<tasks>
<delete dir="${deployRoot}/mydir/${env}"/>
</tasks>
</configuration>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>deployment</id>
<configuration>
<task>
<echo>Deploying website</echo>
</task>
<tasks>
<echo>Copying website artifact to deployment </echo>
<mkdir dir="${deployRoot}/mydir/${env}" />
<unzip
src="${project.basedir}/target/${env}.${project.version}.zip"
dest="${deployRoot}/mydir/${env}" />
<chmod perm="ugo+rx">
<fileset dir="${deployRoot}/mydir/${env}/web-exploded/bin">
<include name="**/*.sh" />
<include name="**/*.bat" />
</fileset>
</chmod>
</tasks>
</configuration>
<phase>deploy</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
pom.xml
中,您定义两种类型的执行:clean
阶段deploy
阶段。顺便请注意,对于 Maven,deploy
确实不意味着在服务器上部署我的(网络)应用程序,但是部署远程存储库上的工件。请阅读部署
插件信息了解更多详细信息。因此,如果您运行命令mvn部署,当Maven生命周期到达
deploy
阶段时,它将运行插件执行(您的pom.xml中的第二个)。
但是,就您而言,您不运行默认的 Maven 生命周期,因为您的命令是 mvn antrun:run (我不考虑
clean
这里的目标,因为它与问题无关)。这可以在 Maven 中转换为运行 antrun 插件,目标是运行。问题是您没有为 Ant 插件的直接调用定义任何配置(其中包含 Ant 任务)。因此有两种解决方案:
install
阶段,然后运行 mvn clean install
而不是mvn antrun:run
。请注意,在这种情况下,您将运行整个 Maven 生命周期(即编译、测试、打包)。
块作为
定义的子级即可。如果您选择第二种解决方案,您将拥有如下所示的
pom.xml
:In your
pom.xml
, you define two types of executions:clean
phasedeploy
phase. Note, by the way, that for Maven,deploy
does not mean deploy my (web-)application on a server but deploy the artifact on a remote repository. Please read thedeploy
plugin information for more details.So if you run the command mvn deploy, when the Maven lifecycle reaches the
deploy
phase, it will run the plugin execution (the second one in yourpom.xml
).However, in your case, you are not running the default Maven lifecycle, as your command is mvn antrun:run (I am not considering the
clean
goal here as it does not matter for the problem). This can be translated in Maven to run the antrun plugin, with the goal run. The problem with that is that you do not define any configuration (which contains the Ant tasks) for a direct call to your Ant plugin.So two solutions:
install
phase, and then run themvn clean install
instead ofmvn antrun:run
. Note that in this case, you will run the whole Maven lifecycle (i.e. compilation, tests, packaging).<configuration>
block to be a child of the<plugin>
definition.If you choose the second solution, you will have a
pom.xml
like this one: