[英]Cannot run Maven using `mvn -D` argument within Microsoft Powershell, but works in Command Prompt
我正在嘗試從命令行構建我們的 web 項目,但跳過了測試。 我正在使用命令mvn clean install -Dmaven.test.skip=true
。
當我從傳統的黑白命令提示符(又名 DOS shell)運行該命令時,該命令有效,但是當我從“Windows PowerShell”的命令運行它時,我收到以下錯誤:
[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]
是什么導致了這種差異?如何使 PowerShell 的行為像傳統的命令提示符一樣?
這是在 Windows 7 上運行。
當您遇到 PowerShell 對要傳遞給控制台 EXE 的 arguments 的解釋出現問題時,請嘗試使用PowerShell 社區擴展附帶的echoargs.exe
實用程序。 使用此工具,您可以看到 PowerShell 如何將 arguments 提供給 EXE,例如:
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>
簡短的回答- 使用引用'-Dmaven.test.skip=true'
根據這個 email 線程:
通常,如果您將 Powershell 用於 Maven、svn 等,您最終將不得不逃避任何 ZDBC11CAABD8BDA99F77E6 以 DAdash882E 開頭的 ZDBC11CAABD8BDA99F77E6 FB4E Powershell 中的轉義字符是反引號。 所以你最終得到 mvn archetype:create `-DgroupId=blah `-DartifactId=blah。 , '-' 是一個特殊字符,當您從 Powershell 控制台運行 maven 時,需要帶反引號的 escaping。
以下對我有用。
$mvnArgs1 ="mvn test -X -Dmaven.test.skip=true".replace('-D','`-D')
Invoke-Expression $mvnArgs1
看起來 -D 是一種特殊字符,需要 escaping。
另請注意,–X 工作正常,不需要 escaping。 注意替換命令中使用單引號,如果使用雙引號(即“),則需要使用``。
我在 windows 7 上使用 Powershell 2.0 (2.0.1.1)
在 PowerShell 中,連字符 (-) 不會被視為 linux 終端,因此您需要在每個連字符前使用此 (`) 對其進行轉義。
例如:-
以下命令在 PowerShell 中不起作用
mvn clean install -Dmaven.test.skip=true
取而代之的是,您需要在連字符 (-) 之前添加此 (`),如下所示
mvn clean install `-Dmaven.test.skip=true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.