# Gradle 2.4-rc-1 fails to retrieve GradleProject model

**URL:** <https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355>\
**Category:** Bugs\
**Tags:** gradle-3293, issue-resolved\
**Created:** [April 27, 2015, 1:09pm UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355 "2015-04-27T13:09:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Attila\_Kelemen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/attila_kelemen/32/12083_2.png) [@Attila\_Kelemen](https://discuss.gradle.org/u/Attila_Kelemen)\
**Post date:** [April 27, 2015, 1:09pm UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/1 "2015-04-27T13:09:15Z")

</div>

I’m adding my custom build model to be queried and if I also query the GradleProject (or IdeaProject or EclipseProject) model, the build fails.

The exception I get is the following: [https://gist.github.com/kelemen/209eafe38ac8820c654d](https://gist.github.com/kelemen/209eafe38ac8820c654d#file-gistfile1-txt).

To reproduce this bug, run “gradlew :netbeans-gradle-default-models:test --tests org.netbeans.gradle.model.java.MultiLevelJavaProjectTest.testBuiltInModels” for [my project](https://github.com/kelemen/netbeans-gradle-project/tree/840ea1e5e56eaffe0d06ddc5b50a48facc29694f) (the link points to a commit where the issue can be reproduced)

This works when using Gradle 2.2 (2.3 has a know bug, so it does not work at all).

---

<div class="post-metadata">

**Author:** ![Attila\_Kelemen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/attila_kelemen/32/12083_2.png) [@Attila\_Kelemen](https://discuss.gradle.org/u/Attila_Kelemen)\
**Post date:** [April 27, 2015, 2:25pm UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/2 "2015-04-27T14:25:02Z")

</div>

It seems that the cause is that I call `project.getTasks().getNames()` before retrieving the models. If I don’t call this method, the models can be retrieved fine. This should mean, that any project calling this method will fail to be loaded through the Tooling API.

---

<div class="post-metadata">

**Author:** ![Attila\_Kelemen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/attila_kelemen/32/12083_2.png) [@Attila\_Kelemen](https://discuss.gradle.org/u/Attila_Kelemen)\
**Post date:** [April 27, 2015, 3:44pm UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/3 "2015-04-27T15:44:53Z")

</div>

Further investigation shows, that its not the `getNames` method which matters but calling `project.getTasks().findByName("dependencyInsight")`. Of course, the best way to reproduce the issue is calling:

```
for (String name: project.getTasks().getNames()) {
    tasks.findByName(name);
}

```

However, I checked and the only problem is calling `findByName` with `"dependencyInsight"` (anything else returned by `getNames()` is not a problem).

---

<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:** [April 28, 2015, 3:33am UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/4 "2015-04-28T03:33:08Z")

</div>

Thanks for the report, looking into it.

---

<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:** [April 28, 2015, 4:53am UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/5 "2015-04-28T04:53:44Z")

</div>

I’ve fixed this. Will post the snapshot build number when it goes out if you want to verify pre rc2.

BTW, if you want to include a 2.4-rc-1 specific patch you need to cast the task container to `TaskContainerInternal` and call `discoverTasks()` before calling `tasks.findByName("dependencyInsight")`. To be clear, this won’t be required for rc2, or final.

---

<div class="post-metadata">

**Author:** ![Attila\_Kelemen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/attila_kelemen/32/12083_2.png) [@Attila\_Kelemen](https://discuss.gradle.org/u/Attila_Kelemen)\
**Post date:** [April 28, 2015, 7:36am UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/6 "2015-04-28T07:36:26Z")

</div>

Thank you. What does `discoverTasks` do (other than working around this issue)? That is, what more tasks can I expect to find with it?

---

<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:** [April 28, 2015, 7:56am UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/7 "2015-04-28T07:56:48Z")

</div>

Tasks added exclusively through rules.

The built in tooling models all do this. At the moment, they offer the only public API for getting all of the executable tasks. This is not a new phenomenon, as even with the old (i.e. not rules based) model just querying the task container at configuration time via the public API didn’t give you everything you could execute.

It’s unclear what public API we’ll offer here at this point beyond the existing public tooling models that do the right thing.

---

<div class="post-metadata">

**Author:** ![Attila\_Kelemen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/attila_kelemen/32/12083_2.png) [@Attila\_Kelemen](https://discuss.gradle.org/u/Attila_Kelemen)\
**Post date:** [April 29, 2015, 8:00am UTC](https://discuss.gradle.org/t/gradle-2-4-rc-1-fails-to-retrieve-gradleproject-model/9355/8 "2015-04-29T08:00:02Z")

</div>

I can verify that the issue has been fixed. Thank you.
