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

**URL:** <https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341>\
**Category:** Help/Discuss\
**Created:** [December 17, 2015, 6:04am UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341 "2015-12-17T06:04:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yann\_Le\_Moigne](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/yann_le_moigne/32/260_2.png) [@Yann\_Le\_Moigne](https://discuss.gradle.org/u/Yann_Le_Moigne)\
**Post date:** [December 17, 2015, 6:04am UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/1 "2015-12-17T06:04:33Z")

</div>

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 :

```gradle
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.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [December 17, 2015, 7:28am UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/2 "2015-12-17T07:28:00Z")

</div>

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"
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![Yann\_Le\_Moigne](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/yann_le_moigne/32/260_2.png) [@Yann\_Le\_Moigne](https://discuss.gradle.org/u/Yann_Le_Moigne)\
**Post date:** [December 17, 2015, 8:03am UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/3 "2015-12-17T08:03:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [December 17, 2015, 8:06am UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/4 "2015-12-17T08:06:05Z")

</div>

I should have mentioned that syntax requires Gradle 2.9.

---

<div class="post-metadata">

**Author:** ![Yann\_Le\_Moigne](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/yann_le_moigne/32/260_2.png) [@Yann\_Le\_Moigne](https://discuss.gradle.org/u/Yann_Le_Moigne)\
**Post date:** [December 17, 2015, 8:39am UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/5 "2015-12-17T08:39:00Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [December 17, 2015, 4:12pm UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/6 "2015-12-17T16:12:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Yann\_Le\_Moigne](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/yann_le_moigne/32/260_2.png) [@Yann\_Le\_Moigne](https://discuss.gradle.org/u/Yann_Le_Moigne)\
**Post date:** [December 17, 2015, 4:42pm UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/7 "2015-12-17T16:42:29Z")

</div>

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](https://discuss.gradle.org/uploads/short-url/i2qBMy4FDSCfs9LmDBIv1wvjzY1.zip) (53.4 KB)

Thanks again for your time and help.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [December 17, 2015, 5:18pm UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/8 "2015-12-17T17:18:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [December 17, 2015, 5:26pm UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/9 "2015-12-17T17:26:55Z")

</div>

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"
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![Yann\_Le\_Moigne](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/yann_le_moigne/32/260_2.png) [@Yann\_Le\_Moigne](https://discuss.gradle.org/u/Yann_Le_Moigne)\
**Post date:** [December 17, 2015, 5:37pm UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/10 "2015-12-17T17:37:00Z")

</div>

Ok, it works.

Thanks you.

---

<div class="post-metadata">

**Author:** ![Anne\_Stellingwerf](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/anne_stellingwerf/32/444_2.png) [@Anne\_Stellingwerf](https://discuss.gradle.org/u/Anne_Stellingwerf)\
**Post date:** [June 13, 2016, 9:14am UTC](https://discuss.gradle.org/t/how-to-read-component-model-information-in-a-copy-task/13341/11 "2016-06-13T09:14:24Z")

</div>

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?
