Execution Block’s Configuration

When you add a plugin to your build you can sometimes rely on its default configuration but more often than not you will want to configure it for your specific project needs. This means providing a configuration block and possibly an execution block.

The execution block is a great way to isolate a configuration to a specific circumstance. Think of it like this.

The root configuration block is for global configuration.

The inner execution configuration block is for locally scoped configuration.

For example:

<plugin>

<groupId>org.example</groupId>

<artifactId>example-plugin</artifactId>

<version>1.0.0</version>

<configuration>

<globalValue>someValue</globalValue>

</configuration>

<executions>

<execution>

<id>doSomething</id>

<phase>generate-sources</phase>

<goals>

<goal>runIt</goal>

</goals>

<configuration>

<localValue>otherValue</localValue>

<globalValue>override</globalValue>

</configuration>

</execution>

<execution>

<id>doSomethingElse</id>

<phase>generate-sources</phase>

<goals>

<goal>runIt</goal>

</goals>

<configuration>

<localValue>otherValue2</localValue>

</configuration>

</execution>

</executions>

</plugin>

Here we have two executions of the same plugin. A global value for the property globalValue is assigned as someValue.

The first execution doSomething assigns a localValue property to otherValue and overrides the globalValue with a value of override.

The second execution doSomethingElse also assigned a localValue property to otherValue2 and then inherits the globalValue.