Home

Awesome

This plugin is no longer maintained! Please consider the Gradle Node Plugin.

Gradle Javascript Plugin!

Aiming to be the simplest way to manage your JavaScript in a build.

Quick Start

Wrangling your JS in a Gradle build is easy! Just add this to your build.gradle file:

Gradle 2.1+

plugins {
  id "com.eriwen.gradle.js" version "2.14.1"
}

Gradle 2.0-

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath "com.eriwen:gradle-js-plugin:1.12.1"
  }
}

apply plugin: "com.eriwen.gradle.js"
// Declare your sources
javascript.source {
    dev {
        js {
            srcDir jsSrcDir
            include "*.js"
            exclude "*.min.js"
        }
    }
    prod {
        js {
            srcDir jsSrcDir
            include "*.min.js"
        }
    }
}

Combining Files (options)

// Configure the built-in task
combineJs {
    encoding = "UTF-8"
    source = javascript.source.dev.js.files
    dest = file("${buildDir}/all.js")
}

// Create new CombineJsTasks if you have multiple sets of JS files
task jsDev(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
    source = ["${projectDir}/js/file1.js", "${projectDir}/js/file2.js"]
    dest = file("${buildDir}/all-debug.js")
}

task jsProd(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
    source = ["${projectDir}/js/file1.js", "${projectDir}/js/file2.js"]
    dest = file("${buildDir}/all.js")
}

Minifying files with Google Closure Compiler (options)

minifyJs {
    source = combineJs
    dest = file("${buildDir}/all-min.js")
    sourceMap = file("${buildDir}/all.sourcemap.json")
    closure {
        warningLevel = 'QUIET'
    }
}

GZip JS (options)

gzipJs {
    source = minifyjs
    dest = file("${buildDir}/all-min.js")
}

JSHint support (options)

jshint {
    source = javascript.source.dev.js.files
    dest = file("${buildDir}/jshint.out")
    reporter = 'checkstyle'
    jshint.options = [expr: "true", unused: "true"]
}

JSDoc 3 support (options)

jsdoc {
    source = ["${projectDir}/js/file1.js", "${projectDir}/js/file2.js"]
    destinationDir = file("${buildDir}/jsdoc")
}

props2js support (options)

props2js {
    source = file("${projectDir}/src/test/resources/test.properties")
    dest = file("${buildDir}/props.jsonp")
    props {
        type = 'jsonp'
        functionName = 'fn'
    }
}

require.js via r.js (options)

requireJs {
    source = javascript.source.dev.js.files
    dest = file("${buildDir}/out.js")
    requirejs.buildprofile = new File("src/main/resources/requirejs-config.js")
}

Built-in Tasks and Options

combineJs

minifyJs (Uses the Google Closure Compiler)

gzipJs

jshint

jsdoc

JSDoc 3 options:
-t or --template <value> The name of the template to use. Default: the "default" template
-c or --configure <value> The path to the configuration file. Default: jsdoc __dirname + /conf.json
-e or --encoding <value> Assume this encoding when reading all source files. Default: utf-8
-T or --test Run all tests and quit.
-d or --destination <value> The path to the output folder. Use "console" to dump data to the console. Default: console
-p or --private Display symbols marked with the @private tag. Default: false.
-r or --recurse Recurse into subdirectories when scanning for source code files.
-h or --help Print this message and quit.
-X or --explain Dump all found doclet internals to console and quit.
-q or --query <value> Provide a querystring to define custom variable names/values to add to the options hash.
-u or --tutorials <value> Directory in which JSDoc should search for tutorials.

props2js

requireJs

What, you want more? Tell me!

Contributors

This project is made possible due to the efforts of these fine people:

See Also

The Gradle CSS Plugin!