How can I link a NativeLibrarySpec library specified in a different build.gradle file to my main build.gradle file?

Previously I had everything in my main build.gradle file. I would like to break it up and have each component have its own build.gradle file, then include those libraries from the sub-components to the main build file.

Before: build.gradle

model.components {
  mainApp(NativeExecutableSpec) {
    sources.cpp.lib library: "lib1", linkage: "static"
    sources.cpp.lib library: "lib2", linkage: "static"
  }
  lib1(NativeExecutableSpec) {
    //defined source set
  }
  lib2(NativeExecutableSpec) {
    //defined source set
  }
}

What I’m trying to do:

build.gradle

model.components {
  mainApp(NativeExecutableSpec) {
    sources.cpp.lib library: ":lib1", linkage: "static"
    sources.cpp.lib library: ":lib2", linkage: "static"
  }

settings.gradle

include libFolder

libFolder/build.gradle

model.components {
  lib1(NativeExecutableSpec) {
    //defined source set
  }
  lib2(NativeExecutableSpec) {
    //defined source set
  }
}

My error now is that the main build.gradle file cannot locate the libraries by the :lib1 name. Can someone tell me what I’m missing or if this is possible? Thanks in advance!

The native-binaries/multi-project sample has an example of this:

It puts everything in the root build.gradle file, but you don’t need to do it that way. Everything within the project(":exe") {} block could just as easily be put inside exe/build.gradle

In your case, you’d have something like in your build.gradle:

model {
    components {
        mainApp(NativeExecutableSpec) {
            sources {
                cpp {
                    lib project: ":libFolder", library: "lib1", linkage: "static"
                    lib project: ":libFolder", library: "lib2", linkage: "static"
                }
            }
        }
    }
}

The important part is that you have to specify the project the component can be found in. The library name will still be the component name.