package org.graphwalker.gradle.plugin.task;

import org.gradle.api.Task;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.TaskAction;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

/**
 * @author Nils Olsson
 */
public class Clean extends TaskBase {

    private final File outputDirectory = new File(getProject().getProjectDir(), "graphwalker");

    @Override
    public Task configure() {
        onlyIf(new Spec<Task>() {
            @Override
            public boolean isSatisfiedBy(Task task) {
                return outputDirectory.exists();
            }
        });
        return this;
    }

    @TaskAction
    public void clean() {
        Path directory = outputDirectory.toPath();
        if (Files.exists(directory)) {
            try {
                Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) throws IOException {
                        Files.delete(file);
                        return FileVisitResult.CONTINUE;
                    }
                    @Override
                    public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
                        Files.delete(dir);
                        return FileVisitResult.CONTINUE;
                    }
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

@@ -599,14 +599,33 @@
     
-onlyIf
+getOutputs().upToDateWhen
 (new
@@ -708,20 +708,23 @@
 By(Task 
-task
+element
 ) %7B%0A    
@@ -742,16 +742,17 @@
  return 
+!
 outputDi

Change the way gradle detects if task is needed to run