Grunt 与 Maven 的集成

Grunt integration with Maven

我在将 G运行t 与 Maven 集成时出现以下错误。我在 Whosebug 上经历过类似的问题,但它对我没有帮助,因此我再次询问。我在项目的根级别有一个 Gruntfile.js 和 package.json 文件。我还在 pom.xml 中添加了用于安装 npm、node 和 g运行t 的相关条目。当我 运行 maven build 时,它确实创建了 2 个文件夹 Node 和 Node_modules 我可以看到 grunt_cli 和其他模块已安装但我仍然遇到错误。

我是 G运行t 和 Node 的新手。请指导,我在这里缺少什么?

错误:- 错误 1 ​​-> 找不到本地 Npm 模块 "grunt-cli"。安装了吗?

错误 2 -> 无法在项目 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 参数。