Definining dependencies in a task

(Abrar Syed) #1


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?


(Peter Niederwieser) #2

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

(Abrar Syed) #3

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.

(Peter Niederwieser) #4

‘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.