Presence of a map as a parameter of the Maven plugin

I am using maven 3 and I want to pass the Map type 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 pass this during configuration:

  <environments> <Testing> <param> unit </param> </Testing> </environments> 

He complains that there is no parameter environment, are you allowed to do this in maven?

+4
source share
1 answer

Have you tried simply removing the alias="environments" attribute?

Another thing is that I'm not sure that Maven will allow you to set the String[] map as a key. I think this will only deal with Map<String, String> (the page here shows only an example of a base map).

In the end, what you can do is resolve the comma separated value instead of 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 an array of String (you can use Apache Commons-lang StringUtils to make it easy):

 /** * @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"}; } 
+5
source

All Articles