BinarySpec.getSources() is empty

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

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

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?

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

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

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

Here is the output from the console

$> 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.

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?