Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run Maven using `mvn -D` argument within Microsoft Powershell, but works in Command Prompt

I am trying to build our web project from the commandline but skipping the testing. I am using the command mvn clean install -Dmaven.test.skip=true.

When I run the command from the traditional black & white Command Prompt (aka DOS shell) the command works, but when I run it from the command from "Windows PowerShell" I get the following error:

[ERROR] Unknown lifecycle phase ".test.skip=true". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin- artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepar e-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, po st-clean. -> [Help 1]

What is causing this discrepancy and how do I get PowerShell to behave like the traditional Command Prompt?

This is running on Windows 7.

like image 484
Sled Avatar asked Jun 14 '11 18:06

Sled


People also ask

Why is mvn command not working?

The “mvn command not found” error mainly occurs when Apache Maven is not installed on your system. Before invoking Maven, you need to ensure that the binary is available on your system path. Let us discuss how we can install and set up Apache Maven on your Linux system. Congratulations!

How do I run a maven command in Windows?

You run Maven by invoking a command-line tool: mvn. cmd from the bin directory of the Maven. To do this conveniently, ${maven. home}\bin must be in your PATH, just like the Java SDK commands.


2 Answers

When you run into problems with PowerShell's interpretation of arguments to be passed to a console EXE, try using the echoargs.exe utility that comes with the PowerShell Community Extensions. With this tool you can see how PowerShell supplies the arguments to the EXE e.g.:

PS> echoargs mvn clean install -Dmaven.test.skip=true Arg 0 is <mvn> Arg 1 is <clean> Arg 2 is <install> Arg 3 is <-Dmaven> Arg 4 is <.test.skip=true>  PS> echoargs mvn clean install '-Dmaven.test.skip=true' Arg 0 is <mvn> Arg 1 is <clean> Arg 2 is <install> Arg 3 is <-Dmaven.test.skip=true> 

Short answer - use quoting '-Dmaven.test.skip=true'

like image 155
Keith Hill Avatar answered Oct 03 '22 03:10

Keith Hill


According to this email thread:

Generally if you are using Powershell for Maven, svn etc you end up having to escape any arguments which start with a dash (-). The escape character in Powershell is a backtick. So you end up with mvn archetype:create `-DgroupId=blah `-DartifactId=blah. , the '-' is a special character that needs escaping with a back-tick when you run maven from Powershell console.

like image 30
katrash Avatar answered Oct 03 '22 03:10

katrash