Why is a tar task considered up-to-date?

I have a task in my scripts that builds some tar artifact. I do not want to run the task if the build is running in a windows environment. So I came up with this construct:

ext.isWindows = Os.isFamily(Os.FAMILY_WINDOWS)
  task tarConfigChuck(type: Tar)
  onlyIf { isWindows == false}
     // ..does the work ..
  assemble {
 dependsOn tarConfigChuck

The effect of it: running my build under a Linux environment considers task tarConfigChuck as UP-TO-DATE. I think this is due

to how “onlyIf” works.

Perhaps the “skip-if-empty” check (which is also reported as “up-to-date”) comes before the ‘onlyIf’ check, and the Tar isn’t configured to contain anything. For such a static check, you can also use ‘enabled = !isWindows’, which might solve the problem (i.e. the task should be reported as “skipped”).

Hi Peter,

sorry, "enabled = “isWindows” does not do the expected. I put in a println statement, and on configuration phase, the output is as expected.

enabled: false, isWindows: true

At build phase, the whole thing is running (checking all dependent projects on Up-to-date).

The output of my task is defined as:

archiveName = 'configchuck.tgz'
    compression Compression.GZIP

and if running under Linux it produces in distribution the required endartefact.

(I do not want to run it in my windows environment because of http://forums.gradle.org/gradle/topics/how_to_overcome_windows_environment_restrictions)

If the task isn’t enabled, it won’t run. (Of course it has to be ‘enabled = !isWindows’, not ‘enabled = isWindows’.) If it does, something is wrong with the build script. Note that ‘enabled’ and ‘onlyIf’ don’t have any effect on dependent tasks (i.e. they will still run).


Note that enabled and onlyIf don’t have any effect on dependent tasks

this was something I didn’t know.

And, because my task “tarConfigChuck” defined a dependency on another user defined task, that latter was triggered. So, I have to conditionally enable that task also. Doing that makes things ok:

:de.uvdms.configchuck:configExport SKIPPED
:de.uvdms.configchuck:tarConfigChuck SKIPPED
:de.uvdms.configchuck:assemble UP-TO-DATE

Thanks for your immediate help, Peter!