Giter Club home page Giter Club logo

gradle-grunt-plugin's Introduction

Gradle plugin for Grunt

This is a very simple Gradle plugin for running Grunt tasks part of the build. It merely wraps calls to "grunt xyz" as "gradle grunt_xyz" tasks. Grunt is installed locally using npm.

Status

  • Build: Build Status
  • Download: Download

Installing the plugin

Releases of this plugin are hosted at BinTray (http://bintray.com) and is part of jcentral repository. Setup the plugin like this:

buildscript {
	repositories {
		jcenter()
	}
	dependencies {
		classpath 'com.moowork.gradle:gradle-grunt-plugin:0.6'
	}
}

Include the plugin in your build.gradle file like this:

apply plugin: 'com.moowork.grunt'

The plugin will also apply grunt-node-plugin for Node and NPM related tasks. (see http://github/srs/grunt-node-plugin for details).

Using the plugin

You can run grunt tasks using this syntax:

$ gradle grunt_build    # this runs grunt build
$ gradle grunt_compile  # this runs grunt compile

... and so on.

These tasks do not appear explicitly in gradle tasks, they only appear as task rule. Your Gruntfile.js defines what grunt_* tasks exist (see grunt --help, or gradle grunt_--help).

Also (more importantly), you can depend on those tasks, e.g.

// runs "grunt build" as part of your gradle build
build.dependsOn grunt_build

This is the main advantage of this plugin, to allow build scripts (and grunt agnostics) to run grunt tasks via gradle.

It is also possible to run a grunt task only if one of its input files have changed:

def srcDir = new File(projectDir, "src/main/web")
def targetDir = new File(project.buildDir, "web")
grunt_dist.inputs.dir srcDir
grunt_dist.outputs.dir targetDir

Extended Usage

If you need to supply grunt with options, you have to create GruntTasks:

task gruntBuildWithOpts(type: GruntTask) {
   args = ["build", "arg1", "arg2"]
}

NPM helpers

The plugin also provides two fixed helper tasks to run once per project, which however require npm (https://npmjs.org/) to be installed:

  • installGrunt: This installs grunt and grunt-cli to the project folder, using "npm install grunt grunt-cli"
  • npmInstall: This just runs "npm install" (possibly useful for scripting)

Since grunt will only be installed in your project folder, it will not interact with the rest of your system, and can easily be removed later by deleting the node_modules folders.

So as an example, you can make sure a local version of grunt exists using this:

// makes sure on each build that grunt is installed
grunt_build.dependsOn 'installGrunt'

// processes your package.json before running grunt build
grunt_build.dependsOn 'npmInstall'

// runs "grunt build" as part of your gradle build
build.dependsOn grunt_build

Automatically downloading Node

To simplify the build, you can say that the plugin should donwload Node and NPM automatically. The dependent gradle-node-plugin does the magic (http://github.com/srs/gradle-node-plugin). Set this configuration to enable:

node {
    // Version of node to use.
    version = '0.10.22'

    // Enabled the automatic download. False is the default (for now).
    download = true
}

Node will be installed in the .gradle folder for current user under nodejs subdirectory.

Getting latest npm on Ubuntu

See https://github.com/creationix/nvm on how to install npm via nvm.

Building the Plugin

To build the plugin, just type the following commmand:

./gradlew clean build

gradle-grunt-plugin's People

Contributors

matf avatar tkruse avatar

Watchers

John Montoya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.