Maven,执行标签,ID标签缺失 [英] maven, execution tag, id tag missing

查看:157
本文介绍了Maven,执行标签,ID标签缺失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看我正在检查的pom的插件部分,发现了这一点:

I'm looking at the plugin section of a pom I'm inspecting and found this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-docck-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>pre-site</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

如果您观察执行部分,您会发现它没有id标记.我的问题是Maven如何使用id标签,以及缺少标签如何影响观察到的行为.我研究了Maven教程,可以推断出不同执行阶段的id必须是唯一的,在pom中不一定跨继承的pom,但是未提及如何使用它.

If you observe the execution section you will notice that it does not have an id tag. My question is how is the id tag used by Maven and how the absence of one influences the observed behavior. I looked into Maven tutorials and could infer that id's of different execution phases must be unique, in a pom not necessarily across the inherited poms, but it did not mention how it is utilized.

推荐答案

至少对于Maven 3.0.x,如果未指定,则执行的ID为default- goalName .因此,对于您拥有的示例,ID为default-check.值default-cli也可以用于配置命令行执行.

For Maven 3.0.x at least, when not specified, the ID for an execution is default-goalName. So for the example you have, the ID would be default-check. The value default-cli may also be used to configure command line executions.

当从POM本身,任何父POM(包括Maven超级POM)和settings.xml创建有效POM时,将使用执行ID. Maven合并了在这些POM中具有相同ID的插件执行的配置.这是一个例子.假设此插件配置位于父POM中(只有Maven超级POM在层次结构中更高.

The execution IDs are used when creating the effective POM from the POM itself, any parent POMs (including the Maven super POM), and settings.xml. Maven merges configuration for plugin executions having the same ID across these POMs. Here's an example. Assume this plugin config is in a parent POM (only Maven super POM is higher up in the hierarchy.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <executions>
    <!-- default-jar is the ID assigned to the jar:jar execution 
         included automatically by Maven.  This demonstrates how we 
         can tweak the built-in plugin executions to meet our needs.  
         Note we do not have to specify phase or goals, as those are 
         inherited.  In the example we add a configuration block and
         change the values of the <forceCreation> and <finalName> 
         elements. -->
    <execution>
      <id>default-jar</id>
      <configuration>
        <finalName>firstJar</finalName>
        <forceCreation>true</forceCreation>
      </configuration>
    </execution>

    <!-- Add an execution of the jar plugin to build a jar with the 
         same contents but different name.  We assign an execution ID.
         Because we are not inheriting config for this execution it's our 
         responsibility to specify phase and goals, as well as the config
         we want.  Executions are run in order so this one will run after 
         the default. -->
    <execution>
      <id>another-jar</id>
      <phase>package</phase>
      <goals>
        <goal>jar</goal>
      </goals>
      <configuration>
        <finalName>duplicateJar</finalName>
      </configuration>
    </execution>

    <!-- Configure plugin behavior if we execute the jar:jar goal 
         directly from the command line.  Don't bind this to a phase; 
         we don't want to run this as part of the normal lifecycle. -->
    <execution>
      <id>default-cli</id>
      <configuration>
        <finalName>cmdLineJar</finalName>
      </configuration>
    </execution>
  </executions>
</plugin>

使用上述配置:

  • mvn clean程序包-生成firstJar.jar和plicateJar.jar
  • mvn jar:jar-构建cmdLineJar.jar(注意,没有干净的生命周期!)
  • mvn clean jar:jar-删除目标目录,构建空(清单除外)cmdLineJar.jar;因为jar:jar不能运行整个生命周期,只是一个目标
  • mvn clean prepare-package jar:jar-通过prepare-package运行生命周期,然后构建一个非空的cmdLineJar.jar

这篇关于Maven,执行标签,ID标签缺失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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