How can I package a native library into a distribution zip?

Hi,

I am building native libraries to be used in other projects. Since there are no native publishing mechanism / plugins so far I create something for myself using the distribution and maven-publish plugin. It looks like this:

tasks.whenTaskAdded { addedTask ->
  if (addedTask.name.startsWith('create') && (addedTask.name.endsWith('StaticLibrary')))
  {
    def artifactName = addedTask.name.substring(6)

    distributions.create(artifactName) { dist ->
      baseName dist.name
      contents {
        from addedTask
      }
      delivery.dependsOn "${dist.name}DistZip"
    }
    publishing.publications.create(artifactName, MavenPublication ) { publication ->
      artifactId artifactName
      // some todo
    }
  }

When tasks are created it checks for the name ‘create…StaticLibrary’ and adds an entry to distributions and publications. This basically works.

My problem is that I did not manage to get the exported headers into the package. I can hard-code it but I would like to get it from the respective component spec, e.g.

googletest(NativeLibrarySpec) {
      sources {
        cpp {
          source {
            srcDir "googletest/googletest/src"
            include "*.cc"
            exclude "gtest-all.cc"
          }
          exportedHeaders {
            srcDir "googletest/googletest/include"
          }
        }
      }

How can I add the files covered by the exportedHeaders spec to my distribution? Do I again have to “string-match” for the respective component? (If yes, how? I have not found it in the object model. :frowning: )

Or, in case this approach does make much sense to you … is there a much cleaner or simpler way - preferably with standard plugins?

Thank you!
Heiko