如何在不强制我在命令行上指定插件的情况下将插件执行链接到Maven中的某个阶段 [英] How do I link a plugin execution to a phase in maven without forcing me to specify plugin on command line

查看:60
本文介绍了如何在不强制我在命令行上指定插件的情况下将插件执行链接到Maven中的某个阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的pom,并在编译中添加了一个ant-run,但是只有在执行以下操作时,它才会执行: mvn install antrun:run
mvn install-不处理蚂蚁运行 mvn antrun:run-不处理蚂蚁运行

I have a simple pom and added an ant-run to the compile but it only executes then when I do the following: mvn install antrun:run
mvn install -- doesn't process the ant-run mvn antrun:run -- doesn't process the ant-run

我认为将插件链接到lifecyce阶段是,当我尝试达到该阶段时将执行该插件.这不是正在发生的事情.

I thought that be linking the plugin to the lifecyce phase that the plugin would be executed when I try to achieve that phase. This is not what is happening.

我错过了一些细微差别,我需要拥有启用该插件的配置文件吗?

感谢您的帮助(下面是pom)

Thanks for the help (pom below)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<build>
    <pluginManagement>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.3</version>
    <executions>    
      <execution>
        <id>antecho</id>
        <phase>compile</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
          <echo message="Hello,world"/>
          </tasks>
        </configuration>
      </execution>
    </executions>

        </plugin>
     </plugins>
    </pluginManagement>
    </build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

推荐答案

您已在<pluginManagement>部分下面指定了插件.这意味着如果直接在build/plugins下(例如在子POM中)声明了插件,则将使用此配置.

You've specified the plugin below the <pluginManagement> section. This means that this configuration will be used if the plugin is also declared directly under build/plugins, for example in a child POM.

要使其在这种情况下起作用,请删除<pluginManagement>标记,以使<plugins>像这样直接位于<build>的下面:

To make it work in this instance remove the <pluginManagement> tags so that <plugins> is directly below <build> like this:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      ...
    </plugin>
  </plugins>
</build>

这篇关于如何在不强制我在命令行上指定插件的情况下将插件执行链接到Maven中的某个阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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