# Execute a CopySpec in a project

**URL:** <https://discuss.gradle.org/t/execute-a-copyspec-in-a-project/25407>\
**Category:** Help/Discuss\
**Created:** [January 10, 2018, 6:45pm UTC](https://discuss.gradle.org/t/execute-a-copyspec-in-a-project/25407 "2018-01-10T18:45:01Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [January 10, 2018, 6:45pm UTC](https://discuss.gradle.org/t/execute-a-copyspec-in-a-project/25407/1 "2018-01-10T18:45:01Z")

</div>

Project has multiple APIs to create a CopySpec but I can’t seem to find an API on Project to execute it.

My project has a task with doLast-blocks, and in there, I want to execute a CopySpec I declared earlier. I did see the with-method to configure a Copy task with a CopySpec, but I can’t change the type of my task to Copy. How can I execute the CopySpec in a task that’s not a member of the AbstractCopyTask hierarchy?

---

<div class="post-metadata">

**Author:** ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)\
**Post date:** [January 14, 2018, 9:25am UTC](https://discuss.gradle.org/t/execute-a-copyspec-in-a-project/25407/2 "2018-01-14T09:25:19Z")

</div>

I believe the Project.copy method is what you want. For example:

```
def mySpec = project.copySpec {
    ...
}
task myCopy {
    doLast {
        project.copy {
            with mySpec
        }
    }
}
```
