无法在 Microsoft Powershell 中使用 `mvn -D` 参数运行 Maven,但可以在命令提示符下运行 [英] Cannot run Maven using `mvn -D` argument within Microsoft Powershell, but works in Command Prompt

查看:37
本文介绍了无法在 Microsoft Powershell 中使用 `mvn -D` 参数运行 Maven,但可以在命令提示符下运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从命令行构建我们的 Web 项目,但跳过了测试.我正在使用命令 mvn clean install -Dmaven.test.skip=true.

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.

当我从传统的 black & 运行命令时白色命令提示符(又名 DOS shell)该命令有效,但是当我从Windows PowerShell"的命令运行它时,出现以下错误:

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] 未知生命周期阶段.test.skip=true".您必须以 <plugin-prefix>:<goal> 格式指定有效的生命周期阶段或目标.或 <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.可用的生命周期阶段有:验证、初始化、生成源、处理源、生成资源、处理资源、编译、处理类、生成测试源、处理测试源、生成测试资源、处理测试资源、测试编译、处理测试类、测试、准备电子包、打包、预集成测试、集成测试、后集成测试、验证、安装、部署、预站点、站点、站点后、站点部署、预清洁、清洁、po圣洁.->[帮助1]

导致这种差异的原因是什么?如何让 PowerShell 像传统的命令提示符一样运行?

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

这是在 Windows 7 上运行的.

This is running on Windows 7.

推荐答案

当您遇到 PowerShell 对要传递给控制台 EXE 的参数的解释的问题时,请尝试使用 echoargs.exe 实用程序附带 PowerShell 社区扩展.使用此工具,您可以查看 PowerShell 如何为 EXE 提供参数,例如:

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>

简短回答 - 使用引用 '-Dmaven.test.skip=true'

这篇关于无法在 Microsoft Powershell 中使用 `mvn -D` 参数运行 Maven,但可以在命令提示符下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆