[Rule based model configuration] Cross-project references

Hello,

I’m currently experimenting with using gradle to build native software.

I have two separate projects, one builds a shared library the other builds an executable. The executable does not have a compile or link time dependency on the shared library but does have a runtime dependency as it loads it dynamically (dlopen).

I would like to have a task in the executable gradle file that copies the shared library alongside the built executable. However I’m struggling to see how this would be possible.

Here’s an example of what I have tried so far:

SharedLibrary/build.gradle

apply plugin: 'cpp'
model {
    components {
        library(NativeLibrarySpec)
    }
}

Executable/build.gradle

apply plugin: 'cpp'
model {
    components {
        executable(NativeLibrarySpec)
    }

    tasks {
        def binary = $.component.executable.binaries.executable

        collate(Sync) {
             group 'Build'
             description 'Collate the executable and its run-time dependencies'

             destinationDir new File(buildDir, 'collate')

             from binary.tasks.link
             from binary.libs.runtimeFiles
             
             // This is the part that, understandably, doesn't work.
             // However is there an alternative?
             into('a-sub-directory') {
                 from project(':SharedLibrary').components.library.binaries.sharedLibrary.tasks.link
             }
        }
    }
}

Now I understand why what I’ve tried doesn’t work; model elements are configured-on-demand, and I’m not giving gradle the correct impetus to configure the shared library.

I also know that this would be trivial if both the executable and shared library were in the same project. However I would like to avoid that if at all possible as it isn’t a true model of the executable/library relationship.

Any help would be greatly appreciated.

Thanks