Grunt与Maven集成

在将Grunt与Maven集成时,我遇到了错误。 我已经经历了类似的问题在stackoverflow,并没有帮助我,因此我再次问。 我在项目的根级有一个Gruntfile.js和package.json文件。 我还在pom.xml中添加了相关条目来安装npm,node和grunt。 当我运行Maven构build时,它确实创build了2个文件夹Node和Node_modules,我可以看到grunt_cli和其他模块已经安装,但仍然出现错误。

我是Grunt和Node的新手。 请指导,我在这里错过了什么?

错误: –错误1 – >本地Npm模块“grunt-cli”未find。 是否安装?

错误2 – >执行目标失败com.github.eirslett:frontend-maven-plugin:0.0.16:grunt(grunt build)项目my_project:无法运行任务:'grunt –no-color'失败。 (错误代码3)

的pom.xml

<build> <plugins> <plugin> <groupId> com.github.eirslett</groupId> <artifactId>frontend-maven-plugin </artifactId> <version> 0.0.16 </version> <configuration> <workingDirectory>${project.basedir}/.. </workingDirectory> </configuration> <executions> <execution> <id> install node and npm </id> <phase> generate-resources </phase> <goals> <goal>install-node-and-npm </goal> </goals> <configuration> <nodeVersion>v0.10.18</nodeVersion> <npmVersion>1.3.8 </npmVersion> </configuration> </execution> <execution> <id> npm install </id> <phase> generate-resources </phase> <goals> <goal> npm </goal> </goals> <configuration> <arguments> install </arguments> </configuration> </execution> <execution> <id> npm run build </id> <goals> <goal>npm </goal> </goals> <configuration> <arguments> run build </arguments> </configuration> </execution> <execution> <id>grunt build </id> <goals> <goal> grunt</goal> </goals> <configuration> <arguments>--no-color</arguments> </configuration> </execution> </executiona> </plugin> <plugins> </build> 

的package.json

 { "name": "myProject", "version": "0.1.0", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "~0.10.0", "matchdep": "~0.3.0", "grunt-ngmin": "0.0.3", "grunt-contrib-uglify": "~0.2.7", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-cssmin": "~0.7.0", "grunt-text-replace": "^0.3.11", "grunt-usemin": "~2.0.0", "mkdirp": "^0.4.1", "moment": "^2.6.0", "grunt-protractor-runner": "^0.2.4", "node-promise": "^0.5.10", "xml2js": "^0.4.3", "request": "^2.36.0", "grunt-cli": "~0.1.11" } } 

尝试从你的pom.xml中删除下面的代码片段

 <execution> <id> npm run build </id> <goals> <goal>npm </goal> </goals> <configuration> <arguments> run build </arguments> </configuration> </execution> 

grunt目标的默认参数是build 。 如果你把参数--no-color你也应该添加build参数。