【问题标题】:Grunt integration with MavenGrunt 与 Maven 的集成
【发布时间】:2016-03-19 02:41:50
【问题描述】:

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

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

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

错误 2 ->无法在项目 my_project 上执行目标 com.github.eirslett:frontend-maven-plugin:0.0.16:grunt (grunt build ):无法运行任务:“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"
    }
}

【问题讨论】:

  • 你试过 frontend-maven-plugin 1.0 吗?您或许应该为所有执行项目添加 generate-resources 阶段。你想达到什么 Maven 的目标?

标签: node.js maven gruntjs npm


【解决方案1】:

尝试从你的 pom.xml 中删除以下 sn-p

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

grunt 目标的默认参数是build。 如果您输入参数--no-color,您还应该添加build 参数。

【讨论】:

    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 2013-10-04
    • 1970-01-01
    • 2015-02-24
    • 2020-09-08
    • 2023-03-23
    相关资源
    最近更新 更多