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

**URL:** <https://discuss.gradle.org/t/defining-gradle-task-input-output-in-generic-classes-without-annotations/23208>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [July 6, 2017, 12:25pm UTC](https://discuss.gradle.org/t/defining-gradle-task-input-output-in-generic-classes-without-annotations/23208 "2017-07-06T12:25:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/marcin/32/1870_2.png) [@Marcin](https://discuss.gradle.org/u/Marcin)\
**Post date:** [July 6, 2017, 12:25pm UTC](https://discuss.gradle.org/t/defining-gradle-task-input-output-in-generic-classes-without-annotations/23208/1 "2017-07-06T12:25:11Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Stefan\_Wolf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/stefan_wolf/32/5519_2.png) [@Stefan\_Wolf](https://discuss.gradle.org/u/Stefan_Wolf)\
**Post date:** [July 6, 2017, 12:39pm UTC](https://discuss.gradle.org/t/defining-gradle-task-input-output-in-generic-classes-without-annotations/23208/2 "2017-07-06T12:39:15Z")

</div>

Hi Marcin,

I guess the [runtime API](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:task_input_output_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.

Cheers,  
Stefan

---

<div class="post-metadata">

**Author:** ![Marcin](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/marcin/32/1870_2.png) [@Marcin](https://discuss.gradle.org/u/Marcin)\
**Post date:** [July 6, 2017, 1:18pm UTC](https://discuss.gradle.org/t/defining-gradle-task-input-output-in-generic-classes-without-annotations/23208/3 "2017-07-06T13:18:14Z")

</div>

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

I don’t know `@CachingTask`, I wanted to use [`@CacheableTask`](https://docs.gradle.org/4.0/javadoc/org/gradle/api/tasks/CacheableTask.html) to enable its caching. Nevertheless from the JavaDoc it seems that `outputs.cacheIf{}` should be also possible to use.

Thanks for your suggestions.

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [July 6, 2017, 2:15pm UTC](https://discuss.gradle.org/t/defining-gradle-task-input-output-in-generic-classes-without-annotations/23208/4 "2017-07-06T14:15:44Z")

</div>

> [@Marcin](#):
>
> The runtime API looks very manual, but it should do its work.

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.
