Defining Gradle task input/output in generic classes (without annotations)

In the plugin I would like to use a configuration class from the core module (which is used by both Gradle and Maven) to define task inputs and outputs. As the core module is Gradle agnostic I cannot use @Input/@Output (which normally I would like to use with @Nested and @CachingTask). I would prefer not to subclass that class to just provide getters with the annotations.

Is there any other way to define inputs/outputs (besides using aforementioned annotations)?

Hi Marcin,

I guess the runtime API for inputs and outputs is what you are looking for. Note that there is no @Nested equivalent at the moment. If you mean @CacheableTask by @CachingTask, then outputs.cacheIf { true } is what you are looking for.


The runtime API looks very manual, but it should do its work.

I don’t know @CachingTask, I wanted to use @CacheableTask to enable its caching. Nevertheless from the JavaDoc it seems that outputs.cacheIf{} should be also possible to use.

Thanks for your suggestions.

I think you’re better off by writing a configuration class for Gradle than wiring all those inputs up by hand. It’ll look cleaner as well. Plus, other Gradle users will find your plugin easier to understand if you use the annotation-based approach.

1 Like