# BinarySpec.getSources() is empty

**URL:** <https://discuss.gradle.org/t/binaryspec-getsources-is-empty/13981>\
**Category:** Help/Discuss\
**Created:** [January 25, 2016, 10:45pm UTC](https://discuss.gradle.org/t/binaryspec-getsources-is-empty/13981 "2016-01-25T22:45:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ethankhall](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ethankhall/32/2564_2.png) [@ethankhall](https://discuss.gradle.org/u/ethankhall)\
**Post date:** [January 25, 2016, 10:45pm UTC](https://discuss.gradle.org/t/binaryspec-getsources-is-empty/13981/1 "2016-01-25T22:45:06Z")

</div>

In a method annotated with `@BinaryTask` I’m trying to access the sources from a BinarySpec. When I do

```gradle
logger.lifecycle("Source Sets: {}", spec.getSources().size());

```

I always get `Source Sets: 0`. I have also used `afterEach` and `all` to try to get the source sets but don’t ever see them.

However when I run `gradle components` I get

```gradle
DefaultTestSchemaComponentSpec 'schema'
------------------------------------------

Source sets
    Test Data Schema Source 'schema:ds'
        srcDir: src/main/dataSource

Binaries
    DefaultTestJavaDataSchemaBinary 'jar'
        build using task: :test:jar

Note: currently not all plugins register their components, so some components may not be visible here.

```

so Gradle see’s the source set but I can’t access it in the plugin. Can anyone tell me what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [January 26, 2016, 12:06am UTC](https://discuss.gradle.org/t/binaryspec-getsources-is-empty/13981/4 "2016-01-26T00:06:32Z")

</div>

Sources should be automatically mapped from the component spec to the binary spec via these rules which are applied by the `ComponentModelBasePlugin`.

> <https://github.com/gradle/gradle/blob/72c942d2eb3a73a30ffa4c4d5d81474302a9a072/subprojects/platform-base/src/main/java/org/gradle/language/base/internal/model/ComponentRules.java#L77-L102>

---

<div class="post-metadata">

**Author:** ![ethankhall](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ethankhall/32/2564_2.png) [@ethankhall](https://discuss.gradle.org/u/ethankhall)\
**Post date:** [January 26, 2016, 12:13am UTC](https://discuss.gradle.org/t/binaryspec-getsources-is-empty/13981/5 "2016-01-26T00:13:04Z")

</div>

Let me see if I can make a simple project that does this so I can share / figure out if I did something wrong.

---

<div class="post-metadata">

**Author:** ![ethankhall](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ethankhall/32/2564_2.png) [@ethankhall](https://discuss.gradle.org/u/ethankhall)\
**Post date:** [January 26, 2016, 1:35am UTC](https://discuss.gradle.org/t/binaryspec-getsources-is-empty/13981/6 "2016-01-26T01:35:11Z")

</div>

Here is a simple example that I made to demo my issue:

> <https://gist.github.com/ethankhall/309854ac3cc6d11e30f9>

Here is the output from the console

```gradle
$> gradle components

:components

------------------------------------------------------------
Root project
------------------------------------------------------------

DefaultSampleComponent 't'
--------------------------

Source sets
    DefaultCustomLanguageSourceSet 't:ss'
        srcDir: src/main/foo

Binaries
    DefaultSampleBinary 'bin'
        build using task: :bin

Note: currently not all plugins register their components, so some components may not be visible here.

BUILD SUCCESSFUL

Total time: 2.456 secs

$> gradle build

:generatebin
[]
:bin
:assemble
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 1.516 secs

```

I would have expected the statement that prints the source sets to have an object in it, even though the source set is empty.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [January 26, 2016, 2:00am UTC](https://discuss.gradle.org/t/binaryspec-getsources-is-empty/13981/7 "2016-01-26T02:00:14Z")

</div>

Looks like it works if you use `getInputs()` rather than `getSources()`. In reality `getSources()` should return the value of `getInputs()` but that’s only on unmanaged binaries that extend from `BaseBinarySpec`. We should probably deprecate `getSources()` (which we’ve done in `BaseBinarySpec`) or bridge this somehow for managed models.

@adammurdoch thoughts?
