JavaExec isn't up-to-date when it should be

It looks like when I have a JavaExec task, the task is never up-to-date. I tried doing what was suggested in but it doesn’t seem to be working.

I have a gist with the example that I’m running into

I expect the generateExample task to be up to date after the first run.

When on Gradle 3.0 I get Value of input property 'environment' has changed for task ':generateExample' which lead me to GRADLE-35281.

If I add task.environment = [:] I get a different message: Output property '$1' file /Users/ethall/temp/output.txt has changed.

If I move back to 2.14.1 I get Output file /Users/ethall/temp/output.txt has changed.

There’s a bug in your example which is causing the output file to always be “modified”. This line:

def output = new FileOutputStream(outputFile)

causes the output file’s content to be cleared during configuration of the task. So Gradle is always seeing it as a different file than what was hashed after the previous task execution.