If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-maven-tasks --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

If no goal is specified, the goal will be set to the target name. This means that the target name must be one of install, deploy or release. For more flexibility with the naming of your targets, and/or having multiple targets with the same goal, specify the goal explicitly.

This task packages and releases an artifact to a maven repository. It will update the version number in the package.json file to the next development version, and, if this is a git project, it will commit and tag the release.

By default, it will increment the version number using the minor version. This can be overridden in the config section using the mode option.

Run this task with the grunt maven:[your-task-target]:major command to bump the next development version using the major version mode.

Run this task with the grunt maven:[your-task-target]:1.2.0 command to release version 1.2.0.

Run this task with the grunt maven:[your-task-target]:1.2.0:major command to release version 1.2.0 and bump the next development version using the major version mode.

The packaging to use when deploying to the maven repository. Will also
determine the archiving type. As internally the grunt-contrib-compress
plugin is used to package the artifact, only archiving types supported
by this module is supported.

In this example, only required options have been specified and the 'goal' is defaulted to the target name.

Running grunt maven:deploy will deploy the artifact to the snapshot-repos folder using the groupId com.example, the artifactId set to the name in package.json and the version set to the version in package.json.

Running grunt maven:release will deploy the artifact to the release-repo folder using the groupId com.example, the artifactId set to the name in package.json and the version set to the version in package.json, but with the -SNAPSHOT suffix removed. The version in package.json will be incremented to the next minor SNAPSHOT version, ie. if it was 1.0.0-SNAPSHOT it will end up at 1.1.0-SNAPSHOT. If this is a git repository, it will also commit and tag the release version, as well as commiting the updated package.json version.

grunt.initConfig({

maven:{

options:{ groupId:'com.example'},

deploy:{

options:{

goal:'deploy',

url:'file://snapshot-repo'

},

src:['**','!node_modules/**']

},

release:{

options:{

goal:'release',

url:'file://release-repo'

},

src:['**','!node_modules/**']

}

}

})

grunt.registerTask('deploy',['clean','test','maven:deploy']);

grunt.registerTask('release',['clean','test','maven:release']);

The maven task can be configured to support deployment or release of multiple artifacts: