java Maven 插件执行 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33278562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 21:28:22  来源:igfitidea点击:

Maven plugin execution ID

javamavengwt

提问by Florian

I have a simple question about execution ID in maven plugin.

我有一个关于 maven 插件中执行 ID 的简单问题。

    <groupId>org.codehaus.mojo</groupId>
    <artifactId>gwt-maven-plugin</artifactId>
    <version>2.7.0</version>
    <executions>
    <execution>
        <id>gwt-process-resources</id>
        <goals>
            <goal>i18n</goal>
            <goal>generateAsync</goal>
        </goals>
    </execution>
</executions>

Can someone explain to me what does this executionId does? How are goals triggered? Can I call directly the "gwt-process-resources" in order to execute both goals? If yes, how can I do that?

有人可以向我解释这个 executionId 有什么作用吗?目标是如何触发的?我可以直接调用“gwt-process-resources”来执行这两个目标吗?如果是,我该怎么做?

采纳答案by Daniel

<id></id>exists only for you to be able to distinguish between other executions. This tag will be displayed when you do the actual build.

<id></id>存在只是为了让您能够区分其他执行。当您进行实际构建时,将显示此标记。

Your execution example will invoke the two goals you have specified: i18nand generateAsync.

您的执行示例将调用您指定的两个目标:i18ngenerateAsync

If the plugin isn't bound to a specific phase(process-resources, package, install, etc) your execution will not performed. The plugin's documentation should tell if this is the case.

如果插件未绑定到特定阶段process-resourcespackageinstall等),你的执行将不会进行。插件的文档应该说明是否是这种情况。

You can specify/override the default phase by using the <phase> tag:

您可以使用<phase> 标签指定/覆盖默认阶段:

...
<execution>
  <id>gwt-process-resources</id>
  <phase>process-resources</phase> <!-- If you need to override -->
  <goals>
    <goal>i18n</goal>
    <goal>generateAsync</goal>
  </goals>
</execution>
...

...

...

Goals are either triggered:

目标要么被触发:

  • Automatically (implicitly by their default phase or explicitly as above)
  • By command line execution: mvn <plugin name>:<goal>
  • 自动(通过默认阶段隐式或如上显式)
  • 通过命令行执行: mvn <plugin name>:<goal>

回答by question_maven_com

Here is a very simple explanation:

这是一个非常简单的解释:

You can not call excecution ids directly

您不能直接调用执行 ID

  mvn gwt-process-resources

will not work since gwt-process-resourcesis just an id.

将不起作用,因为gwt-process-resources只是一个 ID。

If there is no <phase>declaration in the pom then you might want to look at the documentation of the plugin and find the corresponding default phase. If you look at the documentation of the gwt plugin:

如果<phase>pom 中没有声明,那么您可能需要查看插件的文档并找到相应的默认阶段。如果您查看gwt 插件文档

  • gwt:i18n Binds by default to generate-sources.
  • gwt:generateAsync Binds by default to the lifecycle phase: generate-sources.
  • gwt:i18n 默认绑定到生成源。
  • gwt:generateAsync 默认绑定到生命周期阶段:generate-sources。

How are goals triggered?

目标是如何触发的?

if you do

如果你这样做

mvn compile

=> compile > generate-sources in maven lifecycle
=> maven execute gwt:i18n after gwt:generateAsync
=> executed in the order they are declared in pom.xml because they are bound to some phase "generate-sources"

=> 编译 > Maven 生命周期中的生成源
=> Maven 在 gwt:generateAsync 之后执行 gwt:i18n
=> 按照它们在 pom.xml 中声明的顺序执行,因为它们绑定到某个阶段“生成源”

回答by rubens

Some plugins (e.g., compile plugin) will use the "id" in a temporary file name. Therefore, when changing the "id" ensure you don't use characters like ":" that could cause problems formatting a valid file name path.

一些插件(例如,编译插件)将在临时文件名中使用“id”。因此,在更改“id”时,请确保不要使用“:”之类的字符,这可能会导致格式化有效文件名路径的问题。

回答by Raoul Duke

Note that while execution id's have to be unique among all executions of a single plugin within a POM, they don't have to be unique across an inheritance hierarchy of POMs. Executions of the same id from different POMs are merged. The same applies to executions that are defined by profiles.

请注意,虽然执行 ID 在 POM 内单个插件的所有执行中必须是唯一的,但它们在 POM 的继承层次结构中不必是唯一的。来自不同 POM 的相同 id 的执行被合并。这同样适用于由配置文件定义的执行。

https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag

https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag