Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Adding an alternative proposal

...

For example, to configure default execution of the maven jar plugin, settings must be applied to all executions of that plugin.

Code Block
xml
xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <finalName>myjar</finalName>
  </configuration>
</plugin>

This works fine when there is only a single execution of a given plugin goal. But when there are multiple executions, it would often be preferable to be able to apply settings only to the specific execution of the plugin.

Code Block
xml
xml

<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>

...

Currently the only way to configure two command line executions separately is by passing all parameters in through the command line.

Proposal

Proposals

These are the various proposals to solve this issue, in order of being documented:

 Proposal #1

Lifecycle execution defaults

The goal executions attached to the default lifecycle could be given a default execution ID that looks like:

Code Block

default-lifecycle-<goal>

For example the two executions of the compiler plugin would be assigned execution IDs
default-lifecycle-compile
default-lifecycle-testCompile

...

Code Block
[INFO] [compiler:compile {execution: default-lifecycle-compile}]

[INFO] [compiler:testCompile {execution: default-lifecycle-testCompile}]

A potential problem with this is that it is possible in the future that a single goal will need to be bound to the default lifecycle twice. This would cause a name conflict, and would prevent the two goals from being configured separately. This issue is addressed in the next part.

Enhanced command line goal syntax.

In order to link a command line invocation of a plugin with a specific execution in a pom, the goal syntax could be enhanced to include an execution. For example:

Code Block

mvn eclipse:eclipse{execution-1}

This would tell maven to use the configuration contained in "execution-1" of the plugin when running the goal.

In addition, this syntax could be applied to the components.xml file in maven core (where the default plugins are mapped to the lifecycles) to resolve name conflicts in the rare cases where the same goal needs to be applied twice in a default lifecycle.

Proposal #2

This proposal is a counter-proposal to Proposal #1.

Lifecycle execution defaults

The goal executions attached to the default lifecycle for any plugin would be grouped by phase and each phase's execution given a default execution ID that looks like:

Code Block

lifecycle:<packaging>:<phase>

For example the two executions of the compiler plugin in the standard jar packaging would be assigned execution IDs
lifecycle:jar:compile
lifecycle:jar:test-compile

These names will be displayed in Maven's log output like this:

Code Block

[INFO] [compiler:compile {execution: lifecycle:jar:compile}]
[INFO] [compiler:testCompile {execution: lifecycle:jar:test-compile}]

A potential problem with this is that all goals of a plugin bound to a phase must use the same configuration. Another potential problem is that of duplication if the configuration needs to be overridden for both the jar and war packaging. (Two solutions to this are: 1. remove the specification of packaging in the first place (lifecycle:<phase>) 2. use of wildcards (lifecycle:*:<goal>) note that the use of wildcards allows of significant reduction in duplication of configurations that must be different from the plugin's default configuration

No enhanced command line goal syntax.

The issue with invoking executions that are attached to a phase in the lifecycle directly, is that for proper execution of the plugin goal, Maven should really execute all lifecycle phases up to (but not including) the phase that the plugin is bound to... in such a situation, it would seem better to just execute that phase directly, or define a special profile which binds the plugin to early phases (e.g. validate) and specifies the default goal as the highest early phase used so that execution with just specifying the profile would execute the plugin for the task at hand, e.g.

Code Block

<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  ...
  <profiles>    
    <profile>         
      <id>special-checks</id>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <build>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <defaultGoal>validate</defaultGoal>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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