2

To pass parameters containing a list to a Maven build from command line, we can use the "-D" option and pass the values as a comma separated. Maven internally converts this into List, and uses down the line. This has been answered in this question.

However, if the parameters I try to pass has comma (or any other special character like brackets) in them, how should I pass them?

Eg: I need to pass the following 3 strings from command line to Maven build. In the pom it can be done as:

<argsList>
    <arg>Hello</arg>
    <arg>Hello, Hi</arg>
    <arg>Hello (Rohan, Ryan), Hi!</arg>
</argsList>

How do I pass these with the "-D" option? I tried encasing inside single...

mvn compile -Dmyproperty='Hello','Hello, Hi', 'Hello (Rohan, Ryan), Hi!'

and double quotes,

mvn compile -Dmyproperty="Hello","Hello, Hi", "Hello (Rohan, Ryan), Hi!"

but both fail.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
Rohan Bhattacharya
  • 375
  • 1
  • 5
  • 13
  • does this help? https://www.logicbig.com/tutorials/apache-maven/java-compiler-arguments.html – Stephan Jun 26 '18 at 13:23
  • I can set them in the pom. But I need to pass these from the command line, so that I can keep the pom generic.. – Rohan Bhattacharya Jun 26 '18 at 13:28
  • 1
    Sorry I had a brain fart on that one. Check out the accepted answer on this one. basically you quote the entire -D, not just the value. https://stackoverflow.com/questions/7513319/passing-command-line-arguments-from-maven-as-properties-in-pom-xml/33807842 – Stephan Jun 26 '18 at 14:06
  • For which plugins do you try to give those things via command line? Apart from that I would hardly think about this if it is really necessary... – khmarbaise Jun 26 '18 at 15:40
  • @Stephan - Thanks! But I already did try that way. There too the parameters are split into the list based on the comma. Hence I finally get a list like this - `"Hello", "Hello", "Hi", "Hello (Rohan" , "Ryan)", "Hi!"`. Is this splitting Maven's default behavior? Can we modify this somehow? Thanks. – Rohan Bhattacharya Jul 18 '18 at 07:54
  • @khmarbaise - It is a custom plugin which I am working on. – Rohan Bhattacharya Jul 18 '18 at 07:56

0 Answers0