Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not able to pass map kind of variables to maven goal through command line

am trying to pass Map kind of parameters to my maven plugin through command line. Here is how i tried,

$mvn -U -X sample.plugin:hello-maven-plugin:1.0-SNAPSHOT:sayhi -Dsayhi.myMap=key1=value1

$mvn -U -X sample.plugin:hello-maven-plugin:1.0-SNAPSHOT:sayhi -Dsayhi.myMap={key1=value1}

None of these are working and getting following error:

Caused by:
org.codehaus.plexus.component.configurator.ComponentConfigurationException:
Cannot assign configuration entry 'myMap' with value '${sayhi.myMap}' of type
java.lang.String to property of type java.util.Map**

Here is my parameter in Mojo:

/**
 * My Map.
 */
@Parameter(property = "sayhi.myMap", required = false)
private Map<String,String> myMap = new HashMap<String, String>();

followed instructions at ==> https://maven.apache.org/guides/mini/guide-configuring-plugins.html#Mapping_Collections, but no luck., i think am missing something very small. am working on maven v3.2.1

thanks

like image 421
gangadhar mamillapalli Avatar asked Sep 08 '25 06:09

gangadhar mamillapalli


1 Answers

We don't have the option to pass the map variables in the command line as per my knowledge, but you can pass map variable in the following way.

Create xml file and create one plugin (, for XML please refer maven doc)

<myMap>
      <key1>value1</key1>
      <key2>value2</key2>
</myMap>

Your mojo will be:

@Parameter(property = "myMap", required = false)
private Map<String,String> myMap;

Yor maven command will be:

$mvn -s <path_to_xml_file> -U -X sample.plugin:hello-maven-plugin:1.0-SNAPSHOT:sayhi
like image 71
Sireesh Vattikuti Avatar answered Sep 10 '25 08:09

Sireesh Vattikuti