编辑20140716:
找到解决方案
tl; dr = exec-maven-plugin 不 认识 .cmd
文件,但仅限 .bat
文件,作为可执行脚本。改名 grunt.cmd --> grunt.bat
, bower.cmd --> bower.bat
等作为一种解决方法。
做完了 npm install -g grunt-cli
在我的系统上, grunt
最肯定的是 PATH
当我跑 maven install
但是,这似乎没有注册。
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
(build-spa-bower) on project foobar: Command execution failed.
Cannot run program "grunt" (in directory "C:\workspace\foobar\src\main\spa"):
CreateProcess error=2, The system cannot find the file specified -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException:
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
(build-spa-bower) on project foobar: Command execution failed.
只是为了确定,在同一个终端,我已经执行了这个
cd C:\workspace\foobar\src\main\spa
grunt build
...在我发出上面的maven命令的同一个终端中,grunt执行得很好。
是否 exec-maven-plugin
使用 PATH
环境变量,还是需要告诉这个可执行文件以其他方式存在?
编辑:
这个 文件 建议可执行文件 PATH
应该找到,所以它让我更进一步。
除了bguiz的答案,这将是最好的解决方案,我已经使用Maven配置文件创建了一个解决方法,绕过了这个问题。
这是一个临时解决方案,直到maven-exec-plugin的bug得到修复。
请在此处上传错误报告: http://jira.codehaus.org/browse/MEXEC-118
编辑: 该错误已解决,您可以指向1.4-SNAPSHOT来修复它。
<project>
(...)
<profiles>
<profile>
<id>grunt-exec-windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>grunt-default</id>
<phase>generate-resources</phase>
<configuration>
<executable>cmd</executable>
<arguments>
<argument>/C</argument>
<argument>grunt</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
除了bguiz的答案,这将是最好的解决方案,我已经使用Maven配置文件创建了一个解决方法,绕过了这个问题。
这是一个临时解决方案,直到maven-exec-plugin的bug得到修复。
请在此处上传错误报告: http://jira.codehaus.org/browse/MEXEC-118
编辑: 该错误已解决,您可以指向1.4-SNAPSHOT来修复它。
<project>
(...)
<profiles>
<profile>
<id>grunt-exec-windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<id>grunt-default</id>
<phase>generate-resources</phase>
<configuration>
<executable>cmd</executable>
<arguments>
<argument>/C</argument>
<argument>grunt</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
我挖了源代码 exec-maven-plugin
并找到了这个片段。
来源 ExecMojo#getExecutablePath
:
CommandLine toRet;
if ( OS.isFamilyWindows() && exec.toLowerCase( Locale.getDefault() ).endsWith( ".bat" ) )
{
toRet = new CommandLine( "cmd" );
toRet.addArgument( "/c" );
toRet.addArgument( exec );
}
else
{
toRet = new CommandLine( exec );
}
我将此与另一个从maven运行grunt任务的插件进行了比较 发现了这个
if (isWindows()) {
command = "cmd /c " + command;
}
......这对我有用。所以基本上后者是有效的,因为WIndows中的所有命令都是前缀的 cmd /c
,
而 exec-maven-plugin
没有,因为它只对文件结尾 .bat
。
看着 C:\Users\USER\AppData\Roaming\npm
, 我懂了:
node_modules
(夹)
grunt
(unix脚本文件)
grunt.cmd
(Windows脚本文件)
当我重命名 grunt.cmd
- > grunt.bat
,这解决了这个问题,并且 exec-maven-plugin
能够运行此命令。
(这也适用于使用创建的其他可执行文件 npm install -g
, 如 bower
和 yo
)
我对1.5.0的插件有同样的问题。
在我的情况下,原因是我的用户名中的空格导致了一个grunt路径:
C:\ Users \我的名字带有spaces \ AppData \ Roaming \ npm。
当我将npm目录的内容移动到没有空格的路径时,它工作。