Input.files seems ignores file change

I declared the following task:

task dist {
    def bat = file("src/main/run.bat")
    def ownJar = jar.outputs.files.getFiles()
    outputs.dir "${project.buildDir}/dist"
    inputs.files bat, ownJar
    dependsOn jar

    doLast {
        copy {
            from bat
            into "${project.buildDir}/dist"
        }
        copy {
            from sourceSets.main.runtimeClasspath.asFileTree.findAll { it.name.endsWith(".jar") }
            from ownJar
            into "${project.buildDir}/dist/lib"
        }
    }
}

I hoped that the task would run in case the jar changed. Unfortunately I get the message Skipping Task as it is update to date?

I guess I did not get output and input right. Help is appreciated.

oh… I see why, jar.outputs.files.getFiles() is not the name which is actually used (at time of configuration, would be correct in the doLast block though). Is there a neat way to get it? I used the following now (having a multi-module project): "${jar.destinationDir}/${project.name}-${rootProject.version}.jar"

Hi Robert,

You can add the Task directly as an input, no need for querying the files of the output file collection.
Actually, adding jar, jar.outputs or jar.outputs.files as an input would have the desired effect.
I would suggest you do:

input.files jar

You can then also remove the dependsOn jar, since that is automatically inferred.

Cheers,
Stefan

Nice, thanks Stefan, works like a charm