I am using maven 3 and I want to pass in a type Map as a parameter.
I have this in my mojo at the moment:
/**
* @parameter expression="${rep.env}" alias="environments"
* @required
*/
private Map<String,String[]> environments = null;
I am passing in this during the configuration:
<environments>
<Testing>
<param>
unit
</param>
</Testing>
</environments>
It is complaining that it is missing the parameter environments, are you allowed to do this in maven?
pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.
However, as previously mentioned, the user may have a need for third-party plugins. Since the Maven project is assumed to have control over the default plugin groupId, this means configuring Maven to search other groupId locations for plugin-prefix mappings. As it turns out, this is simple.
Did you try to just remove the alias="environments"
attribute?
Another point is that I am not sure that Maven will allow you to set a Map of String[]
as key. I think it will only deal with Map<String, String>
(the page here only shows a basic Map example).
Eventually, what you can do is to allow comma-separated value instead of a String[]
:
<configuration>
<environments>
<one>a,b,c</one>
<two>d</two>
</environments>
</configuration>
and then, when you have to deal with your values, you simply split your String to get a String array (you can use Apache Commons-lang StringUtils to do that easily):
/**
* @parameter expression="${rep.env}"
* @required
*/
private Map<String, String> environments = null;
public void foo() {
String[] values = StringUtils.split(environments.get("one"), ',');
// values == {"a", "b", "c"};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With