Get list of Java files that changed


(Thomas Hirsch) #1

It seems to me like it is not possible to get the list of changed files from the inputs of the compileJava task.

I am getting errors like this:

> No signature of method: org.gradle.api.internal.tasks.DefaultTaskInputs.outOfDate() is applicable for argument types: (build_273udxpl4koqk76bwhxcr9g4y$_run_closure4$_closure20$_closure34$_closure35) values: [build_273udxpl4koqk76bwhxcr9g4y$_run_closure4$_closure20$_closure34$_closure35@27b9ba1e]

or:

> Cannot cast object 'org.gradle.api.internal.tasks.DefaultTaskInputs@6b470c32' with class 'org.gradle.api.internal.tasks.DefaultTaskInputs' to class 'org.gradle.api.tasks.incremental.IncrementalTaskInputs'

I hoped this would work:

compileJava {
    options.incremental = true
    doFirst {
        inputs.outOfDate { changedFile ->
            println changedFile
        }
    }
}

(Thomas Hirsch) #2

I think I found a way:

apply plugin: 'java'
compileJava {
    options.incremental = true
    options.listFiles = true
    logging.addStandardOutputListener(new LogListener(project))
}

class LogListener implements org.gradle.api.logging.StandardOutputListener {
    
    private Project project
    
    public LogListener(Project project) {
        this.project = project
    }

    public void onOutput(CharSequence output) {
        // do whatever with project + output
    }
}