Publishing native exported headers(how to share data between Model elements)

Hi.

I’m using ‘cpp’ plugin to create static library and to publish it:bin + exported headers.
The code Zip task is quite straightforward(assume I have a reference to the instance of StaticLibraryBinarySpec):

tasks {

        zipHeadres(Zip) {

            dependsOn build

            def lib = ... // ????

            def libFile = lib.staticLibraryFile;

            def sets = lib.getInputs();

            sets.all {
                from(it.getExportedHeaders())
            }

            destinationDir = libFile.parentFile

            baseName = libFile.name.replace('.', '_') + "_headers"

            extension = "zip"

        }

When I come to implement the publish task, I again have the same problems:

publishing {

        publications {

            CoreCPP(MavenPublication) {

                groupId = project.ext.groupId
                artifactId = project.ext.artifactId
                version = project.version

                def lib = ... // ????
                def libFile = lib.staticLibraryFile

                artifact(libFile)

                def zipHeadersTask = ... // ????
                def zipFile = zipHeadersTask.archivePath

                artifact (zipFile )
            }
        }
    }

My questions are:

  1. How can I get a reference to StaticLibraryBinarySpec instance in zip task ?
  2. How can I reference to StaticLibraryBinarySpec and Zip in publish task ?
  3. How to make publish task depends on zip task ?

I tried to use global properties (project.ext) but it fails due to order of excution.

Thanks
Boaz