Getting CoffeeScript Compilation Working in Gradle

| Comments

Gradle 1.2 includes support for compiling CoffeeScript but it’s not well documented, there’s nothing on the gradle website and all I was able to find after a bunch of googling was a gradle-dev thread where Luke Daley announces the functionality.

Based on that thread, I was able to come up with this sample gradle file that let me compile my .coffee source files into javascript as part of a build:

import org.gradle.plugins.javascript.coffeescript.CoffeeScriptCompile

apply plugin: 'coffeescript-base'

repositories {
  maven {
    url: ""

task compileCoffee(type: CoffeeScriptCompile) {
  source fileTree('src/main/coffee')
  destinationDir file('build/js')

To integrate this into a war file, you’d need to extend it a little further to make the war task depend on the compileCoffee task, and then tell it to include the output in build/js in the root of the war.

I wasn’t able to use this approach on my current project for a couple of reasons related to restricted maven repos, and ended up using require-cs plugin for require.js AMD module framework as I was already using it.