How to make a JavExec task incremental in gradle?

74 views Asked by At

I have a JavaExec task in my build.gradle file and it doesn't follow incremental build.

Is there a way to make JavaExec tasks incremental, just like how JavaCompile tasks are made incremental?

Let me know your thoughts.

Thank you!

1

There are 1 answers

0
Cisco On

If it is a custom task type that extends JavaExec, then you could add the @CacheableTask annotation:

@CacheableTask
public abstract class MyCustomTask extends JavaExec { }

Another approach if it is just a JavaExec task, as described in the Javadocs:

https://docs.gradle.org/current/javadoc/org/gradle/work/DisableCachingByDefault.html

Caching for individual task instances can be enabled and disabled via TaskOutputs.cacheIf(String, Spec) or disabled via TaskOutputs.doNotCacheIf(String, Spec). Using these APIs takes precedence over the presence (or absence) of @DisableCachingByDefault.

tasks.register<JavaExec>("myTask") {
    outputs.cacheIf {
        // some condition...
    }
}