Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Migrating from 1.1.x to 1.2.x

Bastian Voigt edited this page Apr 14, 2014 · 5 revisions

Since version 1.2.0 grunt-maven-plugin no longer ships with crude Grunt task for Maven+Grunt integrated workflow. Instead please use grunt-maven-plugin NPM Grunt multitasks.

Motivation behind this change is delivering elastic workflow tasks that can be easily combined with all the other Grunt tasks and good practices (like having per-environment targets). Crude tasks from 1.1.x used some hacks and actually changed running Grunt config to call other plugins. NPM tasks approach is much cleaner and easier to comprehend for frontend developers.

...and probably those tasks will be reused in upcoming grunt-gradle-plugin ;)

Migrating Gruntfile.js

Loading tasks

Instead of loading crude task:

grunt.loadTasks('maven-tasks');

Install and load NPM tasks, in package.json add grunt-maven task dependency:

"devDependencies": {
  "grunt-maven": "~1.1.0",
}
grunt.loadNpmTasks('grunt-maven');

Configuration

Instead of loading and configuring one maven task, you should use preprocessing and postprocesing tasks: mavenPrepare and mavenDist.

Configuration should change from:

  maven: {
    warName: '<%= gruntMavenProperties.warName %>'
    dist: {
      dest: 'dist',
      src: ["<%= pkg.name %>*.js", "js/**", "!js/test/**"]
    },
    maven: {
      src: ["./**"]
    },
    watch: {
      tasks: ['default']
    }
  }

/*...*/

grunt.registerTask('default', ['jshint', 'karma', 'less', 'uglify' 'maven']);

to:

  /* equivalent of deprecated maven section */
  mavenPrepare: {
    options: {
      resources: ['**']
    },
    all: {}
  },

  /* equivalent of deprecated warName and dist sections */
  mavenDist: {
    options: {
      warName: '<%= gruntMavenProperties.warName %>',
      deliverables: ["<%= pkg.name %>*.js", "js/**", "!js/test/**"],
      gruntDistDir: 'dist'
    },
    all: {}
  }

/*...*/

grunt.registerTask('default', ['mavenPrepare', 'jshint', 'karma', 'less', 'uglify', 'mavenDist']);

Note that mavenPrepare has to be called first in task queue and mavenDist is last.

Watch

1.2.x version of grunt-maven-plugin no longer supports maven-watch Grunt task. Instead you should create own configuration using well known grunt-contrib-watch:

  gruntMavenProperties: grunt.file.readJSON('grunt-maven.json'),

  watch: {
    maven: {
      files: ['<%= gruntMavenProperties.filesToWatch %>'],
      tasks: 'default'
    }
  }

Notice reading grunt-maven.json. This file contains properties derived from pom.xml and is used internally by NPM tasks. It also includes a helper properties filesToWatch, which is a globing pattern that point to /src/main/webapp/... , depending of what static dir was configured in pom.xml.