[ http://jira.codehaus.org/browse/MNG-3356?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=138511#action_138511 ]
Paul Cager commented on MNG-3356: --------------------------------- I've investigated this further (see Apache's list: http://mail-archives.apache.org/mod_mbox/commons-user/200805.mbox/[EMAIL PROTECTED]). In summary I think version 1.1 is so broken that it is impossible to handle multiple "-D" type arguments. I think changing to use "hasArgs()" (plural) just makes cli 1.1 fall over in a different way. Here's an extract of the email I sent to Apache: As far as I can see it is simply not possible to use commons-cli to parse repeating options, such as occur in ant: ant -Dproperty1=value1 -Dproperty2=value2 compile Cli *does* have a junit test for ant-type options, but it unfortunately doesn't catch the error because it tests the command line: ant -Dproperty1=value1 -Dproperty2=value2 -projecthelp I attach a patch for the junit test (Cli-junit.patch) that will provoke the error, if you want to try it yourself. _Here's what I think is happening:_ The unit test (and the work-around suggested in issue 137) creates the "D" option using "hasArgs()" [note the 's' on the end of the method name]. Using hasArgs() for the "D" option causes cli to assume that all arguments following the "-D" (until it encounters another option) belong to the "-D" option. I've probably not explained that clearly so here's an example: ant -Dproperty1=value1 -Dproperty2=value2 compile will treat "compile" as though it was "-Dcompile". getArgs() will return 0 elements, rather than one ("compile"). If instead you construct the "D" option using hasArg() [singular] then it will *not* interpret the second "-D" as an option. getArgs() will return 2 elements: "property2=value2" and "compile". getOptionValues() will return only the first -D value. This problem first came to light when Debian upgraded CLI from 1.0 to 1.1, and caused Debian's Maven package to fail (the standard Maven package uses cli 1.0 of course). As part of the Debian packaging I have created a quick-and-dirty patch which allows Maven to work (see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=469082 for the Debian bug report, and I have attached the patch (MultiOptions.patch). I would guess that a proper fix would be rather more elegant than my patch. > Multiple -Dkey=value command line options not handled correctly > --------------------------------------------------------------- > > Key: MNG-3356 > URL: http://jira.codehaus.org/browse/MNG-3356 > Project: Maven 2 > Issue Type: Bug > Components: Command Line > Affects Versions: 2.0.8 > Reporter: Christian Koelle > Priority: Critical > Fix For: 2.0.x > > Attachments: command-line.patch > > > After upgrading to 2.0.8 on Debian the handling of multiple (more than one) > -Dkey=value cli options fail, i.e. something like: > mvn plugin:goal -Dkey1=value1 -Dkey2=value2 > fails with: > Invalid task 'key2=value2': you must specify a valid lifecycle phase, or a > goal in the format plugin:goal or > pluginGroupId:pluginArtifactId:pluginVersion:goal -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira