# How to make a task return some value and how to get it in java

**URL:** <https://discuss.gradle.org/t/how-to-make-a-task-return-some-value-and-how-to-get-it-in-java/4537>\
**Category:** Old Forum Archive\
**Created:** [October 9, 2012, 2:23pm UTC](https://discuss.gradle.org/t/how-to-make-a-task-return-some-value-and-how-to-get-it-in-java/4537 "2012-10-09T14:23:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeevin](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jeevin](https://discuss.gradle.org/u/Jeevin)\
**Post date:** [October 9, 2012, 2:23pm UTC](https://discuss.gradle.org/t/how-to-make-a-task-return-some-value-and-how-to-get-it-in-java/4537/1 "2012-10-09T14:23:00Z")

</div>

Let me explain my problem,

1.i have a java class from which i ll invoke a gradle task(using projectConnection) . That gradle task will generate a json object. Now i want that json object in my java class. How to get it? any ideas?

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:** [October 10, 2012, 6:41am UTC](https://discuss.gradle.org/t/how-to-make-a-task-return-some-value-and-how-to-get-it-in-java/4537/2 "2012-10-10T06:41:00Z")

</div>

Typically, tasks produce something more durable than an in-memory object. So you are using the tooling API? The best solution I’m aware of is writing the JSON to a file. Then you can also enable up-to-date checks for the task.

---

<div class="post-metadata">

**Author:** ![Jeevin](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jeevin](https://discuss.gradle.org/u/Jeevin)\
**Post date:** [October 10, 2012, 3:46pm UTC](https://discuss.gradle.org/t/how-to-make-a-task-return-some-value-and-how-to-get-it-in-java/4537/3 "2012-10-10T15:46:00Z")

</div>

yes… I’m using the gradle tooling… Without writing to file. is there anyway??

I’m trying to use ProjectBuilder in gradle to get the Project object.(My intention is like using project object directly acessing the data i need) but the project Object contains nothing ☹
