# Exec Task is UP-TO-DATE when it shouldn't be

**URL:** <https://discuss.gradle.org/t/exec-task-is-up-to-date-when-it-shouldnt-be/12829>\
**Category:** Help/Discuss\
**Created:** [November 18, 2015, 11:52pm UTC](https://discuss.gradle.org/t/exec-task-is-up-to-date-when-it-shouldnt-be/12829 "2015-11-18T23:52:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edeesis](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/edeesis/32/3886_2.png) [@edeesis](https://discuss.gradle.org/u/edeesis)\
**Post date:** [November 18, 2015, 11:52pm UTC](https://discuss.gradle.org/t/exec-task-is-up-to-date-when-it-shouldnt-be/12829/1 "2015-11-18T23:52:12Z")

</div>

Hello!

I’ve been working on getting our builds gradle-ized, and a coworker ran into this problem, and now I’ve hit it too. Here’s what we have:

```
def pullCommonDir = new File(buildDir, 'repo')
task pullCommon(type:Exec) {
    outputs.file "${pullCommonDir.path}/versions
    executable = 'perl'
    args = ['pull_common.pl', '-f']
}

```

The reason we have this Perl script is mostly for legacy but what you need to know is:

- The script creates a file called ‘versions’ in the ‘repo’ folder, each time it’s run
- Other things are in the repo folder too, but not really important to the question

Here’s the result of doing clean then pullCommon:

```
C:\Project> gradlew clean pullCommon
:clean
:pullCommon UP-TO-DATE

```

How does that work? Clean clears out the buildDir, but it says we’re still up to date?

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [November 19, 2015, 12:33am UTC](https://discuss.gradle.org/t/exec-task-is-up-to-date-when-it-shouldnt-be/12829/2 "2015-11-19T00:33:15Z")

</div>

I suspect that `pull_common.pl` sometimes doesn’t create ‘build/repo/versions’, but doesn’t fail either. In that case, the output file does not exist and the task completed successfully, so that looks like the output of the task is for ‘build/repo/versions’ to not exist. If that’s the case, just running `gradlew pullCommon` should also be up-to-date.

I’d check if `pull_common.pl` creates the path to the versions file, if it doesn’t, then I think perl silently fails to write anything.

If you don’t want to touch `pull_common.pl`, you could wrap this into a custom task (roughly something like this):

```gradle
class PerlVersions extends DefaultTask {
   @OutputFile 
   File getOutputFile() { 
      return new File(buildDir, "repo/versions") 
   }
   @TaskAction
   def exec() {
      project.exec { // do perl thing 
      }
   }
}

```

And I think Gradle will automatically create the path to the output file this way.

---

<div class="post-metadata">

**Author:** ![edeesis](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/edeesis/32/3886_2.png) [@edeesis](https://discuss.gradle.org/u/edeesis)\
**Post date:** [November 19, 2015, 2:24am UTC](https://discuss.gradle.org/t/exec-task-is-up-to-date-when-it-shouldnt-be/12829/3 "2015-11-19T02:24:33Z")

</div>

Yup, I think you’re right on the money. I changed the pullCommon script to return 1 when there’s an error (it was returning 0 before for some reason), so hopefully I won’t run into this anymore. Sounds like I just have to force the task again, and I won’t run into this problem.

Thanks!
