apache/maven · error · IllegalArgumentException

Failed to parse command line options: {}

Error message

Failed to parse command line options: {}

What it means

Starting the Maven interactive shell (mvnsh) failed at option parsing: ShellParser parses the shell launcher's own arguments with CommonsCliShellOptions and rethrows any ParseException as IllegalArgumentException 'Failed to parse command line options'. Main Maven build options are not involved; only flags passed to the shell launcher are.

Source

Thrown at impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnsh/ShellParser.java:31

 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.maven.cling.invoker.mvnsh;

import org.apache.commons.cli.ParseException;
import org.apache.maven.api.cli.Options;
import org.apache.maven.cling.invoker.BaseParser;

public class ShellParser extends BaseParser {
    @Override
    protected Options parseCliOptions(LocalContext context) {
        try {
            return CommonsCliShellOptions.parse(context.parserRequest.args().toArray(new String[0]));
        } catch (ParseException e) {
            throw new IllegalArgumentException("Failed to parse command line options: " + e.getMessage(), e);
        }
    }
}

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Run the shell launcher's help to see accepted options.
  2. Strip build options from the invocation and set them inside the shell session instead.
  3. Fix the specific token named in the message.

Example fix

# before: build flags passed to the shell launcher
mvn sh -DskipTests -pl app

# after: plain launch; set options inside the shell
mvn sh
Defensive patterns

Strategy: try-catch

Try / catch

try {
    new ShellParser().parseCliOptions(context);
} catch (IllegalArgumentException e) {
    showShellUsageAndExit(e.getMessage());
}

Prevention

When it happens

Trigger: Passing build-style flags (-D, -pl, -am) to the shell launcher, an unrecognized long option, or a flag missing its value.

Common situations: Shell aliases/wrappers that append build options to every Maven-family command including `mvn sh`; flags copy-pasted from mvn usage.

Understand the failure class

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/bda3e7aa7f7c5e98. Report an issue: GitHub.