While working with the Native plugins, I’m searching for ways to copy the output of a native task, but can’t seem to get it working. It looks as if the native tasks are created too late.
Assume we have native (cpp) component ‘x’. There will be a lifecycle task ‘xStaticLibrary’. I would expect I can do this:
task zipX(type:Zip) {
from project.tasks['xStaticLibrary']
into '.'
}
Unfortunately this will not configure successful, claiming that task with name ‘xStaticLibrary’ cannot be found. Yet, when I execute ‘./gradlew components’, I do see the component and it’s corresponding tasks. How would I get this working?
UPDATE:
I similarly tried this, but it failed saying that the BinarySpec with name ‘:x’ cannot be found:
task zipX(type:Zip) {
from project.binaries['x'].staticLibraryFile
into '.'
}
Thanks @mark_vieira , this did indeed work, back when you posted it (on Gradle 2.6). However, when running the same code on 2.10, it fails during configuration: Could not find property 'binaries' on task ':acllib:nativeZip'.
From release notes, I can’t figure out what I should change to get it back working. Mind help me out?
Yes the syntax has changed in recent versions. You’ll have to do something like this:
model {
tasks {
zipAllNativeSOs(Zip) {
$.binaries.withType(StaticLibraryBinarySpec).each {
// Attach them all
from it.staticLibraryFile
dependsOn it.tasks
}
}
}
}
I am using Gradle 2.10 and it is in a model block, but it’s not the same model block as where I define the native components. Would that pose a problem?
My build script is over 2100 lines long. I posted fragments of it on this Gist, but can’t show the entire file (as it’s IP of my employer). I’m afraid you won’t be able to run it…
It results in a compilation error with regards to the line that says binaries {:
Exception thrown while executing model rule: model.tasks > create(nativeZip)
Attempt to mutate closed view of model of type ‘java.lang.Object’ given to rule ‘model.tasks’