Jshint task always has no source files


(ian.durkan) #1

I’m trying to use the Gradle JS Plugin https://github.com/eriwen/gradle-js-plugin to run jshint against my Javascript codebase. However, the task refuses to actually run, saying it has no source files. Here’s an excerpt from my build.gradle:

javascript.source {
    dev {
        js {
            srcDir webAppDirName + "/js/"
            include "**/*.js"
        }
    }
}
  println ("*****
" + javascript.source.dev.js.files)
  jshint {
    source = javascript.source.dev.js.files
    jshint.predef = ['$': false, 'd3': false]
    dest = project.file("${buildDir}/foobar.txt")
    ignoreExitCode = false
}

When I run ‘gradle jshint --info’ I get the following relevant output:

Selected primary task 'jshint'
Tasks to be executed: [task ':widgets:jshint']
:widgets:jshint
Skipping task ':widgets:jshint' as it has no source files.
:widgets:jshint UP-TO-DATE

The println indicates that javascript.source.dev.js.file contains a list of the expected .js files. What do I need to do to make this task run jshint for me? Thanks.

Note that the build.gradle where this code is located is for a subproject ‘widgets’ that builds a .war for my application. I’m using the 1.5.1 version of the plugin.


(Ciaran Liedeman) #2

I had/have the same issue. I connected a debugger to the gradle jvm and set a breakpoint on the getSource method of SourceTask and found that the source field was always an empty array. I could not figure out why but I did find this work around:

task myJshint(type:com.eriwen.gradle.js.tasks.JsHintTask) {

source javascript.source.dev.js.files

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

outputToStdOut false

reporter ‘checkstyle’

ext {

options = [expr: “true”, unused: “true”]

}

}

But this still doesn’t not explain the no source files error.

I am using gradle version 1.7 and also 1.5.1 version of the plugin.

Ciaran