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

(ylemoigne) #1


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.

(Mark Vieira) #2

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"

(ylemoigne) #3

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.

(Mark Vieira) #4

I should have mentioned that syntax requires Gradle 2.9.

(ylemoigne) #5

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)

(Mark Vieira) #6

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

(ylemoigne) #7

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: $ (53.4 KB)

Thanks again for your time and help.

(Mark Vieira) #8

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

(Mark Vieira) #9

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"

(ylemoigne) #10

Ok, it works.

Thanks you.

How to copy output of binary task
testSuites not seeing non-api classes
(Anne Stellingwerf) #11

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?