How would you create the model-component closure in a custom plugin since the 2.3 native-component changes?

How can I recreate the new 2.3-rc-2 “model” closure which contains a CppSourceSet inside my plugin? I used to be able to do something like project.libraries.create but I’m not sure how to create or access the components piece.

This boils down to how do you add a sourceset to a component container? Im trying to do something like the following:

project.model {
    project.extensions.rs.libs.each { l ->
        components.create(
            l.name, NativeLibrarySpec.class, {
                 sources {
                    l.sources(project)
                }
            }
        )
    }
}

or

project.model {
    project.extensions.rs.libs.each { l ->
        components {
            l.name(NativeLibrarySpec) {
                 sources {
                    l.sources(project)
                }
            }
        )
    }
}

where l.name is just the string name of the binary and sources(project) will return the sourceset.

1 Like

This is all very much work in progress and is undocumented. It will also require quite a lot of effort on your side to implement it and you will have to get your hands dirty with going through a lot of Gradle source and tests to understand the mechanisms. It’s also very probable that it will change slightly for the next (2.4) release and you will have to rework it again.

Please confirm that you are still interested in this before I invest my time in outlining how to approach this.