Question

Hi i am working with grunt and Maven .

used plugin to start 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>

this plugin is not working to start grunt when i start maven project.

Grunt file :-

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'
    ]);
};

Please help to run it ..

Était-ce utile?

La solution

here is an article that describes how to setup maven to work with grunt: http://addyosmani.com/blog/making-maven-grunt/

it also includes an example setup script:

<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>

Autres conseils

In my experience, the frontend maven plugin is far and away the best plugin for this type of build/deploy process. 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>

One thing to be aware of it is will download node for the system it is being run on, so if you have a different OS on your build server, you'll need to make sure that is the version you have checked into version control, your local version (for me OSX) will have to be maintained local to your project.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top