Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the implicit ID of a maven plugin execution?

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.

like image 700
Jens Bannmann Avatar asked Jan 04 '16 11:01

Jens Bannmann


People also ask

What is Maven plugin execution?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.

What is the correct syntax for executing a Maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”.

What is plugin tag in Maven?

Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects. They do this by executing an "action" (i.e. creating a WAR file or compiling unit tests) in the context of a project's description - the Project Object Model (POM).

What are the two types of Maven plugins?

Introduction. In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.


1 Answers

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

like image 100
A_Di-Matteo Avatar answered Oct 14 '22 07:10

A_Di-Matteo