grunt无法使用maven插件

时间:2014-02-17 12:57:25

标签: node.js maven gruntjs maven-plugin

您好我正在与grunt和Maven合作。

使用插件启动Grunt

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <phase>${basedir}/scripts/gruntFiles</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>grunt</executable>
    </configuration>
</plugin>

当我启动maven项目时,这个插件无法启动grunt。

Grunt档案: -

var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;

module.exports = function (grunt) {
    require('load-grunt-tasks')(grunt);
    require('time-grunt')(grunt); 

    grunt.initConfig({
        yeoman: {
            // configurable paths
            app: require('./bower.json').appPath || 'app',
            dist: 'src/main/webapp/resources/dist'
        },
        watch: {
            compass: {
                files: ['src/main/scss/{,*/}*.{scss,sass}'],
                tasks: ['compass:server', 'autoprefixer']
            },
            styles: {
                files: ['src/main/webapp/styles/{,*/}*.css'],
                tasks: ['copy:styles', 'autoprefixer']
            },
            livereload: {
                options: {
                    livereload: 35729
                },
                files: [
                    'src/main/webapp/resources/scripts/rrh/authoring/basket_app/directives/templates/*.html',
                    '.tmp/styles/**/*.css',
                    '{.tmp/,}src/main/webapp/resources/scripts/**/*.js',
                    'src/main/webapp/resources/images/**/*.{png,jpg,jpeg,gif,webp,svg}'
                ]
            }
        },

        pkg: grunt.file.readJSON('package.json'),

        // Define our source and build folders
        js_directives_path_rrh_ui: "../rrh/rrh-ui/directives",
        js_src_path_home_rrh: "../rrh",

        //output folder path
        js_output_folder_path: "../gruntOutputFiles",

        // Grunt Tasks
        concat: {
            options:{
                separator: ';',
                mangle: false,
                compress: true, linenos: false,
            },
            // used for home page internal js files
            js: {
                src: ['<%= js_src_path_home_rrh %>/common/rrh-common.js',
                      '<%= js_src_path_home_rrh %>/rrh-ui/directives/RrhUiDirectives.js'
                     ],
                dest: '<%= js_output_folder_path %>/home_app.js'
            },
        },
        uglify: {
            options:{
                mangle: false,
                compress: true, linenos: false,
                banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version + "\\n" %>'
            },
            // used for home page internal js files
            js: {
                src: '<%= concat.js.dest %>',
                dest:'<%= js_output_folder_path %>/home_app.min.js'
            },
        });

    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-concat');

    grunt.registerTask('server', function (target) {
        grunt.task.run([
            'concat',
            'uglify',
            'watch'
        ]);
    });

    grunt.registerTask('build', [
        'concat',
        'uglify',
    ]);

    grunt.registerTask('default', [
        'build'
    ]);
};

请帮助运行它..

2 个答案:

答案 0 :(得分:1)

这是一篇描述如何设置maven以使用grunt的文章: http://addyosmani.com/blog/making-maven-grunt/

它还包括一个示例安装脚本:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.2.1</version>
  <executions>
    <execution>
      <phase>prepare-package</phase>
      <goals>
        <goal>exec</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <executable>grunt</executable>
  </configuration>
</plugin>

答案 1 :(得分:0)

根据我的经验,前端maven插件远远不是这种类型的构建/部署过程的最佳插件。 https://github.com/eirslett/frontend-maven-plugin

<plugin>
    <groupId>com.github.eirslett</groupId>
    <artifactId>frontend-maven-plugin</artifactId>
    <version>...</version>

    <!-- optional -->
    <configuration>
        <workingDirectory>src/main/frontend</workingDirectory>
    </configuration>

   <execution>
    <id>grunt build</id>
    <goals>
        <goal>grunt</goal>
    </goals>

    <!-- optional: the default phase is "generate-resources" -->
    <phase>generate-resources</phase>

    <configuration>
        <!-- optional: if not specified, it will run Grunt's default
        task (and you can remove this whole <configuration> section.) -->
        <arguments>build</arguments>
    </configuration>
</execution>
</plugin>

有一点需要注意的是它将为正在运行的系统下载节点,因此如果您的构建服务器上有不同的操作系统,您需要确保这是您拥有的版本检查版本控制,您的本地版本(对于我OSX)将必须在您的项目本地维护。