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 c开发者_StackOverflowomplaining that it is missing the parameter environments, are you allowed to do this in maven?
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"};
}
精彩评论