# Best way to get SourceSet for a Task (specifically JavaCompile)

**URL:** <https://discuss.gradle.org/t/best-way-to-get-sourceset-for-a-task-specifically-javacompile/27997>\
**Category:** Help/Discuss\
**Created:** [August 2, 2018, 7:40pm UTC](https://discuss.gradle.org/t/best-way-to-get-sourceset-for-a-task-specifically-javacompile/27997 "2018-08-02T19:40:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgoldberg](https://avatars.discourse-cdn.com/v4/letter/r/5f8ce5/32.png) [@rgoldberg](https://discuss.gradle.org/u/rgoldberg)\
**Post date:** [August 2, 2018, 7:40pm UTC](https://discuss.gradle.org/t/best-way-to-get-sourceset-for-a-task-specifically-javacompile/27997/1 "2018-08-02T19:40:09Z")

</div>

What is the best way to get the `SourceSet` for a `Task` (specifically `JavaCompile`)?

Is it possible for `JavaCompile` (or any other `Task`) to have more than one `SourceSet`? If so, is there a different methodology for getting multiple `SourceSet`s for a `Task` than for getting the standard single `SourceSet` for a `Task`?

---

<div class="post-metadata">

**Author:** ![st\_oehme](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/st_oehme/32/5249_2.png) [@st\_oehme](https://discuss.gradle.org/u/st_oehme)\
**Post date:** [August 3, 2018, 9:59am UTC](https://discuss.gradle.org/t/best-way-to-get-sourceset-for-a-task-specifically-javacompile/27997/2 "2018-08-03T09:59:23Z")

</div>

That’s the wrong way round - The task is a low-level construct and has no knowledge about where it came from. In fact, the Android plugin reuses this task without reusing our SourceSet concept at all.

You can get the task for a SourceSet though, using `SourceSet.getCompileJavaTaskName`
