# Definining dependencies in a task

**URL:** <https://discuss.gradle.org/t/definining-dependencies-in-a-task/5600>\
**Category:** Old Forum Archive\
**Created:** [August 3, 2013, 3:38am UTC](https://discuss.gradle.org/t/definining-dependencies-in-a-task/5600 "2013-08-03T03:38:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abrar\_Syed](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/abrar_syed/32/599_2.png) [@Abrar\_Syed](https://discuss.gradle.org/u/Abrar_Syed)\
**Post date:** [August 3, 2013, 3:38am UTC](https://discuss.gradle.org/t/definining-dependencies-in-a-task/5600/1 "2013-08-03T03:38:00Z")

</div>

Hi

Background: I am working on a gradle plugin wherethe user specifies an SDK version in an extension object. Based upon this version, I download the SDK in a task, and read a json file (shipped with the SDK) which specifies the dependencies of the SDK. These dependencies are in the standard gradle dependency notation. Because I download the SK in a task, I don’t have access to the dependency json file until the execution phase. CUrrently I have a ‘resolvSDKDeps’ task which the compile task depends on, which adds the dependencies to the compile configuration. However, the dependencies don’t show up when I run ‘gradle dependencies’ nor are the dependencies detected by any IDEs when i try to import the project. (using the IDE integration, not the gradle IDE plugins).

now for the actual question: Is it viable to continue to grab the dependencies at execution time with a task? or should I be trying to download the SDK and add the dependencies in the evaluation phase?

thanks

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [August 3, 2013, 5:03pm UTC](https://discuss.gradle.org/t/definining-dependencies-in-a-task/5600/2 "2013-08-03T17:03:00Z")

</div>

Doing this in the configuration phase is not an option, as it would then happen for every single build invocation.

---

<div class="post-metadata">

**Author:** ![Abrar\_Syed](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/abrar_syed/32/599_2.png) [@Abrar\_Syed](https://discuss.gradle.org/u/Abrar_Syed)\
**Post date:** [August 4, 2013, 2:47am UTC](https://discuss.gradle.org/t/definining-dependencies-in-a-task/5600/3 "2013-08-04T02:47:00Z")

</div>

But then is there any way to define the dependencies during the execution phase in such a way that ‘dependencies’ task detects the dependencies? like an afterEvaluate{} block? or is that just as bad as the configuration phase?

Its worth mentioning that users define their SDK version with 2 fields, Base version, and API version, and so the actual version of the API is resolved between these two separate versions during the afterEvaluate{} block.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [August 4, 2013, 4:15am UTC](https://discuss.gradle.org/t/definining-dependencies-in-a-task/5600/4 "2013-08-04T04:15:00Z")

</div>

‘afterEvaluate’ _is_ run in the configuration phase.

I can think of two potential solutions to your problem:

- Keep configuring dependencies with a task, and make tasks such as ‘dependencies’, ‘eclipseClasspath’, and ‘ideaModule’ depend on that task.

- Ship the dependency list (also) with the plugin. Then the plugin can configure the dependencies in the configuration phase.
