How to "read" component model information in a Copy task?

Hi,

I would like to create an “export” task for native libraries which would copy :

  • the output of the releaseMainStaticLibrary and debugMainStaticLibrary to $buildDir/export/lib
  • the exportedHeaders of main sourceset to $buildDir/export/includes

But I’m stuck with the component model, I don’t see in the API/doc how to read this information… I tried something like :

task export(type: Copy) {
	from model.components.main.sources.exportedHeaders
	from releaseMainStaticLibrary
	into "${buildDir}/export"
}

But for the first from, it seems I can’t read the model like that.
For the second from, it seems the task don’t exist at configuration phase.

Thanks for any help.

Should look something like this. I’m assuming the ‘c’ plugin here. If using ‘cpp’, ‘objective-c’, etc, modify the name of the source set as necessary.

model {
    tasks {
        export(Copy) {
            from($.components.main.sources.c.getExportedHeaders()) {
                into 'includes'
            }
            from($.tasks.createReleaseMainStaticLibrary) {
               into 'lib'
            }
            into "${buildDir}/export"
        }
    }
}

Thanks Mark, as usual you’re the first who come to the rescue ;).

Gradle don’t like the $ in $.components and $.tasks …
Invalid variable name. Must include a letter but only found: $

I tried different variation, without success.

I should have mentioned that syntax requires Gradle 2.9.

Ho it’s me, excuse me, I forgot my basic rules for asking question…
I should have mentioned the gradle version I use : 2.10-rc-1 (using gradlew)
(But I can revert to 2.9 if needed)

Really 2.9 or newer. Gradle 2.10 should be working fine. Can you share your full example?

Yes, of course.
In attachement, a full exemple.
gradle tasks (which is gradle 2.9 in my setup) works fine
gradlew tasks fail with Invalid variable name. Must include a letter but only found: $

test.zip (53.4 KB)

Thanks again for your time and help.

I’m now able to recreate this issue in Gradle 2.10. We are going to investigate this.

Here’s a workaround which should work with 2.10.

model {
    tasks {
        export(Copy) {
            into('includes') {
                from $.components.main.sources.cpp.getExportedHeaders()
            }
            into('lib') {
                from $.tasks.createMainReleaseStaticLibrary
            }
            into "$buildDir/export"
        }
    }
}

Ok, it works.

Thanks you.

I’m trying the workaround in Gradle 3.0 M1, but it renders the same error message.
What’s the proper way of doing this, and does it work?