Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What references the <id> value of a Maven plugin execution?

Tags:

java

maven

In a Maven <plugin> element there is an <executions> element which contains multiple <execution> elements. Each <execution> element can have an <id> element containing a string. What references those <id>...</id> elements? What does it mean to omit that element? What are the semantics of the <id> element?

For example:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>default-jar-execution</id>
            <configuration>
              <finalName>mainjar</finalName>
            </configuration>
          </execution>
          <execution>
            <id>extra-jar-execution</id>
            <goals>
              <goal>jar</goal>
            </goals>
            <configuration>
              <finalName>anotherjar</finalName>
            </configuration>
          </execution>
        </exectutions>
      </plugin>
      [...]
    </plugins>
  </build>
</project>

What references those <id>default-jar-execution</id> and <id>extra-jar-execution</id> values? What is the behavioral difference of changing either of those strings? What does it mean to remove those elements?

like image 978
jameshfisher Avatar asked Oct 28 '14 13:10

jameshfisher


2 Answers

The id element has two functions:

  1. Documentation
  2. Allow Maven to know when you want to create a new execution and when you want to modify an existing one.

The first case is simple: It just allows you to give the execution a meaningful name.

The second case means that Maven comes with default executions which you can see when you run mvn help:effective-pom, for example. If you want to replace/extend an existing execution, you need to use the same id. Maven will then merge the two.

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

Executions of the same id from different POMs are merged.

like image 137
Aaron Digulla Avatar answered Nov 02 '22 13:11

Aaron Digulla


For sake of completeness, I would note, that since Maven 3.3.1 (March 2015), there is also an option to use the execution-id, when calling maven specific goal from the command line.

See https://maven.apache.org/docs/3.3.1/release-notes.html

See discussion about this option here

like image 29
Eliyahu Machluf Avatar answered Nov 02 '22 13:11

Eliyahu Machluf