What is the implicit ID of a maven plugin execution?
Asked Answered
A

1

15

To disable a plugin execution inherited by the parent POM, one can override it as follows:

<execution>
    <id>TheNameOfTheRelevantExecution</id>
    <phase/>
</execution>

Now what if the parent POM does not define an explicit execution ID? This answer says that "If you don't specify id for execution, Maven will do it implicitly (in a way not expected intuitively by you)." So how are execution IDs generated by Maven? Bonus points for linking the relevant Maven source code.

Note: I'm not looking for alternative ways to disable a plugin execution.

Anhydrous answered 4/1, 2016 at 11:46 Comment(0)
Y
26

By default, Maven will create an execution id applying the following patterns depending on different cases:

  • Execution id set to: default-cli for plugin:goals executed from the command line
  • Execution id set to: default-<goal_name> for plugin:goals executed as part of the binding defined by a specific packaging
  • Execution id set to: default for plugin:goals executions as part of the POM which didn't specify any id.

If you execute the Maven Dependency Plugin from the command line, for instance, with the classic mvn dependency:tree goal, you will notice the default-cli execution id:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ project ---

If you look at the output of any Maven build and at the default executions for the Maven Compiler Plugin during the compile phase, for instance, you will notice default-compile and default-testCompile as execution ids of the compile and testCompile goals of the Maven Compiler Plugin.

The same pattern is applied to all default plugins/goals executed by Maven as part of the binding defined for a given packaging. Execution ids are always between curved brackets right after the concerned plugin and goal name.
For instance, an extract of a basic Maven build:

[INFO] --- maven-clean-plugin:2.5:clean (default-clean)
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) 
[INFO] --- maven-surefire-plugin:2.19:test (default-test)  

Shows how the execution ids (last token in the snippet above, between brackets) are always following this pattern.

Finally, if you configure an execution of any plugin in your POM without specifying an id, you will notice the default id applied by Maven:

[INFO] --- exec-maven-plugin:1.1:java (default) @ project ---

From official Maven documentation:

Command line execution id

each mojo invoked directly from the command line will have an execution Id of default-cli assigned to it, which will allow the configuration of that execution from the POM by using this default execution Id

Default binding execution id

each mojo bound to the build lifecycle via the default lifecycle mapping for the specified POM packaging will have an execution Id of default-goalName assigned to it

Default plugin execution id

the default value of the executionId - literally set to default in the POM model - was meant to provide some of this functionality. Unfortunately, this solution was never tested to make sure it worked with the use cases above; they fell through the cracks during testing. Now, with the release of Maven 2.2.0 (and later, Maven 3.0), these use cases can finally be addressed


Last but not least, concerning execution ids, since Maven 3.3.1 you can even point to a particular execution id of your POM from the command line using the new @executionId operator

Younker answered 4/1, 2016 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.