1

I have some task:

task foo {
    //Do something
}
foo.dependsOn(":bar:baz")
foo.dependsOn(":bar2:baz2")

This task should only run on windows. I know, I could do:

import org.apache.tools.ant.taskdefs.condition.Os

task foo {
    if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
        return;
    }
    ...
}

But this would still trigger the execution of the dependency tasks (:bar:baz and :bar2:baz2).

How can I avoid this?

JCWasmx86
  • 3,473
  • 2
  • 11
  • 29
  • 1
    You could basically add `onlyIf { !Os.isFamily(Os.FAMILY_WINDOWS) }` to the *foo* task, but that would still execute *baz* and *baz2*. Gradle is like that. You'd have to add the `onlyIf` to the dependency tasks, too. – barfuin Jan 21 '21 at 09:57
  • 2
    Or you declare the dependency only when not on Windows. – barfuin Jan 21 '21 at 10:16
  • Thanks for your reply, I now just wrapped the entire `foo.dependsOn(...)` lines into a `if(Os.isFamily(Os.FAMILY_WINDOWS)) {...}`. – JCWasmx86 Jan 21 '21 at 11:23

0 Answers0