1

I wrote a maven plugin that I'm using on some projects. In the first project, it only has one execution and I can execute the plugin directly with

mvn com.mycompany:my-plugin:0.0.1-SNAPSHOT:do-stuff

In the second project, the plugin has multiple executions and when I try the above command, I end up blowing up because the plugin tries to execute with empty parameters.

Note that in both cases, the plugin works fine when executed as part of the process-resources phase. It only fails when I try to execute just the plugin goal. Can someone help me understand why the second example tries to execute with blank parameters?

First project (one execution - works fine):

        <plugin>
            <groupId>com.mycompany</groupId>
            <artifactId>my-plugin</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <configuration>
                <sourceFiles>
                    <sourceFile>loadfile</sourceFile>
                </sourceFiles>
                <outputFile>outputFile</outputFile>
            </configuration>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>do-stuff</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Second project (multiple executions - does not wok):

<plugin>
        <groupId>com.my-company</groupId>
        <artifactId>my-plugin</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <executions>
            <execution>
                <id>default</id>
                <phase>process-resources</phase>
                <configuration>
                    <sourceFiles>
                        <sourceFile>file1</sourceFile>
                    </sourceFiles>
                    <outputFile>outputFile</outputFile>
                </configuration>
                <goals>
                    <goal>do-stuff</goal>
                </goals>
            </execution>
            <execution>
                <id>novice</id>
                <phase>process-resources</phase>
                <configuration>
                    <sourceFiles>
                        <sourceFile>file1</sourceFile>
                        <sourceFile>file2</sourceFile>
                    </sourceFiles>
                    <outputFile>outputFile</outputFile>
                </configuration>
                <goals>
                    <goal>do-stuff</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
Alex Pritchard
  • 4,260
  • 5
  • 33
  • 48

1 Answers1

1

In the second example, the only configuration you have is in executions. There's no configuration block outside the execution bindings, so invoking the plugin goal directly naturally receives no params (since the present configuration blocks are specific to the bindings).

A solution would be to have a "default" configuration block (as in your first example) + execution-specific configs, or providing configuration params from the command line, if applicable.

As a final note - and not intending to insult, every programmer misses simple solutions sometimes - since it's your plugin, you can just change the configuration spec to let you define everything you need in one configuration block :). I don't think you should necessarily do this given that the only reason seems to be your specific problem with m2e, but it's certainly an option on the table.

mikołak
  • 9,605
  • 1
  • 48
  • 70
  • Is there a way to just have it do all the executions, short of running the whole goal phase? – Alex Pritchard Jul 17 '13 at 18:24
  • 1
    Small nitpick, "goal" is what your plugin defines, "phase" is what the goal's executions are bound to. Unfortunately, I'm not aware of such a solution, outside of a shell script that invokes `mvn` twice with the goal and different configuration arguments in the command line. But your question raises a red flag: are you sure you're not trying to use Maven for something it is not intended for? What's the scenario here? – mikołak Jul 17 '13 at 18:33
  • Thanks for the clarification. We have a plugin that executes during process-resources phase to prepare an additional resource. This is fine from CLI, but the plugin is not yet M2E aware, so we want to be able to make an eclipse launch that just runs all the plugin executions. I figured out I can just create a launch for mvn process-resources and that works fine, but I was still curious if there was a way to just perform all the plugin executions (not that we do anything else in process-resources). – Alex Pritchard Jul 17 '13 at 18:38
  • Ah, m2e lifecycle mapping issues, how I love them... The answers [to this question](http://stackoverflow.com/questions/6352208/how-to-solve-plugin-execution-not-covered-by-lifecycle-configuration-for-sprin) should help you in this case. Also, invoking a Maven Run Configuration directly should also work fine as well, you should only see problems when invoking the "Eclipse-specific" `Build`. – mikołak Jul 17 '13 at 18:44
  • 1
    TYVM, I'll take a look. – Alex Pritchard Jul 17 '13 at 18:47