4

If I have multiple executions of a Maven plugin and they share at least one of the same configuration values, is there a way for me to share this configuration between all executions of the plugin.

Consider the trivial case of a build plugin with two executions:

<plugin> <!-- ID, version... --> <executions> <execution> <id>ID1</id> <configuration> <myConfig>foo</myConfig> ... </configuration> </execution> <execution> <id>ID2</id> <configuration> <myConfig>foo</myConfig> ... </configuration> </execution> </executions> </plugin> 

How can I rewrite this so that both the ID1 and the ID2 executions use the same value for the myConfig configuration?

2
  • Is this supposed to actually read <id>ID2</id> for the second <execution>? (if so then it will answer my question, which is not what you asked but shows how to get around the error I am getting when trying to build my jar with two executions in the same plugin :) ) Commented Feb 12, 2014 at 19:20
  • tested it in my own code with same id and it throws a duplicate execution.id error. Edited this question to show that execution id's must be different. Commented Feb 12, 2014 at 19:26

2 Answers 2

6

Why not move common configuration outside concrete executions?

<plugin> <!-- ID, version... --> <configuration> <commonConfig>foo</commonConfig> </configuration> <executions> <execution> <id>ID1</id> <configuration> <specificConfig>bar</specificConfig> </configuration> </execution> <execution> <id>ID1</id> <configuration> <specificConfig>baz</specificConfig> </configuration> </execution> </executions> </plugin> 

It works for some plugins I use (e.g. gmaven-plugin) and in Maven documentation I haven't found any evidence it shouldn't work.

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't seem to work for the exec-maven-plugin. When configuration is defined for the execution any external configuration is ignored.
I get the following error with maven-exec-plugin: 'profiles.profile[my-profile].plugins.plugin.[org.codehaus.mojo:exec-maven-plugin].executions.execution.id' must be unique but found duplicate execution with id ID1 So apparently, multiple executions must have different ids.
1

Use properties that are set like this somewhere before they are used:

<project> ... <properties> <myConfig>foo</myConfig> </properties> ... </project> 

Then use it like this

<execution> <id>ID1</id> <configuration> <myConfig>${myConfig}</myConfig> ... </configuration> </execution> <execution>     <id>ID2</id>     <configuration>         <myConfig>${myConfig}</myConfig>          ...     </configuration> </execution> 

2 Comments

Thanks for the answer, but to be honest, I actually already do this exact behaviour with the <properties> tag. I'm instead looking for a way to share the <configuration> tag between multiple executions.
Though it seems reasonable that would be allowed, I know of no way to do that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.