Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having a map as a Maven plugin parameter

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?

like image 507
jcw Avatar asked Jun 10 '11 09:06

jcw


People also ask

What is the difference between plugin and pluginManagement tags?

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.

Does Maven allow third party plugins?

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.


1 Answers

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"};
}
like image 144
Romain Linsolas Avatar answered Oct 18 '22 03:10

Romain Linsolas