exec-maven-plugin says cannot run specified program, even though it is on the PATH

前端 未结 3 1352
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 14:24

Edit 20140716:

Solution found

tl;dr = exec-maven-plugin does not recognise .cmd files, but only .bat file

3条回答
  •  情书的邮戳
    2021-01-11 14:58

    I dug into the source code of exec-maven-plugin and found this snippet.

    From the source of 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 );
        }
    

    I compared this to another plugin that ran grunt tasks from maven, and found this

            if (isWindows()) {
                command = "cmd /c " + command;
            }
    

    ... and that worked for me. So essentially the latter worked because all commands in WIndows were prepended with cmd /c, whereas the exec-maven-plugin did not, because it only did so for file ending in .bat.

    Looking in C:\Users\USER\AppData\Roaming\npm, I see:

    • node_modules (folder)
    • grunt (unix script file)
    • grunt.cmd (windows script file)

    When I rename grunt.cmd --> grunt.bat, this solves the problem, and exec-maven-plugin is able to run this command.

    (this also applies to other executables created using npm install -g, such as bower and yo)

提交回复
热议问题