# Task declaration order and multi-projects

**URL:** <https://discuss.gradle.org/t/task-declaration-order-and-multi-projects/4370>\
**Category:** Old Forum Archive\
**Created:** [December 6, 2011, 3:41pm UTC](https://discuss.gradle.org/t/task-declaration-order-and-multi-projects/4370 "2011-12-06T15:41:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Jurgens](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Michael\_Jurgens](https://discuss.gradle.org/u/Michael_Jurgens)\
**Post date:** [December 6, 2011, 3:41pm UTC](https://discuss.gradle.org/t/task-declaration-order-and-multi-projects/4370/1 "2011-12-06T15:41:00Z")

</div>

Hi,

I have a question concerning task declaration order and multi-projects.

We use gradle in a multi project environment. Common build functionality is placed in a non-project directory beside the subprojects.

This common build functionality is included in the main project gradle file via

```gradle
subprojects {
 apply from: "$rootDir/include/jar.gradle"
}

```

The file jar.gradle contains for example a custom task “CollectDeploymentDescriptor” and a configured task “collectDeploymentDescriptor”:

```gradle
task collectDeploymentDescriptor(type: CollectDeploymenDescriptors) {
 ...
}
  class CollectDeploymenDescriptors extends DefaultTask {
 ...
}

```

When an additonal tasks in a subproject “framework” of type “CollectDeploymentDescriptor” is defined, the following error occurs

```gradle
Cause: Could not find property 'CollectDeploymenDescriptor' on project ':framework'.

```

It seems that the order of task declaration is bad for me. Do you have an idea to solve my problem?

Best regards, Michael

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [December 6, 2011, 3:47pm UTC](https://discuss.gradle.org/t/task-declaration-order-and-multi-projects/4370/2 "2011-12-06T15:47:00Z")

</div>

Classloaders are isolated between scripts to prevent pollution and conflicts by plugins.

The solution is to assign the class object to a project property and reference that way…

In ‘jar.gradle’:

```gradle
class CollectDeploymenDescriptors extends DefaultTask {
    ...
}
  project.collectDeploymentDescriptors = CollectDeploymentDescriptors

```

Then in your other build.gradle:

```gradle
task customCollectDeploymentDescriptors(type: collectDeploymentDescriptors)

```

In short, classes defined in a build script are not available by name to any other build script.

---

<div class="post-metadata">

**Author:** ![Michael\_Jurgens](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@Michael\_Jurgens](https://discuss.gradle.org/u/Michael_Jurgens)\
**Post date:** [December 7, 2011, 7:46am UTC](https://discuss.gradle.org/t/task-declaration-order-and-multi-projects/4370/3 "2011-12-07T07:46:00Z")

</div>

Works fine! Thank you.
