Gradle-js-plugin


(John Cartwright) #1

Hello All,

I’m trying to get started w/ the gradle-js-plugin using the jshint task and gradle 1.7. I have a definition like

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

where “source” seems to be getting the correct file list, however the jshint task is reporting “it has no source files”.

I did see that gradle is giving several warnings re: dynamic properties, but that doesn’t seem to be the issue here.

Can someone please point out what I’m doing wrong here? Complete script listed below.

Thanks!

–john

// Pull the plugin from Maven Central
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.eriwen:gradle-js-plugin:1.5.1'
    }
}
  apply plugin: 'war'
apply plugin: 'jetty'
apply plugin: 'js'
  def jsSrcDir = "source/javascripts"
  repositories {
    mavenCentral()
}
  dependencies {
    compile group: 'commons-io', name: 'commons-io', version: '1.4'
    compile group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}
  httpPort = 8080
stopPort = 9451
stopKey = 'foo'
  // Declare your sources
javascript.source {
    dev {
        js {
            srcDir jsSrcDir
            include "*.js"
            exclude "*.min.js"
        }
    }
    prod {
        js {
            srcDir jsSrcDir
            include "*.min.js"
        }
    }
}
  jshint {
    source = javascript.source.dev.js.files
    def dest = file("${buildDir}/jshint.out")
    reporter = 'checkstyle'
    jshint.options = [expr: "true", unused: "true"]
}

(Peter Niederwieser) #2

What are you getting the dynamic property warnings for?


(Matthew Rusinak) #3

I ran into this. Basically, the jshint block is creating a task for you; however, the jshint.options is a global object.

Try this:

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

(John Cartwright) #4

Thanks for the suggestion Matthew, but I’m still getting the same response.

–john


(John Cartwright) #5

Thanks for your interest Peter. Here are the warnings:

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "source" on "com.eriwen.gradle.js.JsHintExtension_Decorated@7a9eb4a1", value: "[/Users/jcc/quickstart...".
[/Users/jcc/quickstart/source/javascripts/main.js, /Users/jcc/quickstart/source/javascripts/module.js]
Deprecated dynamic property: "reporter" on "com.eriwen.gradle.js.JsHintExtension_Decorated@7a9eb4a1", value: "checkstyle".

–john


(Peter Niederwieser) #6

According to the message, the ‘jshint’ extension doesn’t have a ‘source’ or ‘reporter’ property. Probably it’s a name collision between the ‘jshint’ extension and the ‘jshint’ task, and you’ll have to use ‘tasks.jshint { … }’.


(Seth Kraut) #7

This worked for me with Gradle 1.7.

jshint {

tasks.jshint.source = javascript.source.dev.js.files

tasks.jshint.dest = file("${buildDir}/jshint.out")

tasks.jshint.reporter = ‘checkstyle’

tasks.jshint.ignoreExitCode=true

jshint.options = [bitwise:true]

jshint.predef=[“Ext”:1] }


(John Cartwright) #8

Thanks Seth, this seems to work for me as well.

–john