How do I get a file list from C plugin's source set?

Hi,

I’ve been using Gradle for some months now (starting from Gradle 2.2).

Amongst others I use the C plugin.

I use a non-supported compiler in parallel with gcc.
For both I use the standard mechanism to build source sets.
The custom compiler is fed with a file list build from the source sets.

With Gradle 2.2 I can print out such a list with

task printSources << {
    sources.main.c.source.each { src ->
        println project.relativePath(src.path)
    }
}

In the meantime some things changed and Gradle 2.3 provides componentSpec which lets me use a similar syntax.

How can I do it with Gradle 2.5, however?

The configuration - to keep it simple - is:

model {
    components {
        main(NativeLibrarySpec) {
            sources {
                c {
                    source {
                        srcDirs "src/main"
                        include "*.c"
                    }
                }
            }
        }
    }

I found a hint in the release notes but I feel somehow lost in darkness…

Thx in advance!

Okay, I found it by myself :wink:

I use this now:

project.properties.sources.withType(CSourceSet).find { it.parentName == 'main' }.source

… and my builds are happy again.

Is there another way to do it?

As time goes by Gradle continued to develop…

My builds aren’t happy any more with 2.10 :frowning:

How can it be done now?

Okay, I realized it :joy:

project.modelRegistry.realize('components.main.sources.c', CSourceSet).
                      getSource().getFiles()

Alternatively:

project.modelRegistry.find('components.main.sources.c', CSourceSet).
                          getSource().getFiles()