# 2.10-rc2: copy into projectDir fails

**URL:** <https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378>\
**Category:** Bugs\
**Created:** [December 18, 2015, 9:54pm UTC](https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378 "2015-12-18T21:54:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chefhoobajoob](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@chefhoobajoob](https://discuss.gradle.org/u/chefhoobajoob)\
**Post date:** [December 18, 2015, 9:54pm UTC](https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378/1 "2015-12-18T21:54:27Z")

</div>

I have this task definition in a cpp native binaries model with a single NativeLibrarySpec component:

```gradle
    tasks {
        export(Copy) {
            from( $.components.main.sources.cpp.getExportedHeaders() ) {
                into 'Include'
            }
            from( $.tasks.createMainReleaseStaticLibrary ) {
                into 'Lib'
            }
            into "$projectDir"
        }
    }

```

Running this task fails with this error:

```gradle
FAILURE: Build failed with an exception.

* What went wrong:
Failed to capture snapshot of output files for task 'export' during up-to-date check. See stacktrace for details.
> Failed to create MD5 hash for file C:\Users\hoobajoob\Documents\Visual Studio 2013\Projects\project-x\.gradle\2.10-rc-2
\taskArtifacts\cache.properties.lock.

```

…if I then change the destination from `$projectDir` to `$buildDir` or any subdirectory of the project directory like `$projectDir/foo`, it executes successfully.

---

<div class="post-metadata">

**Author:** ![chefhoobajoob](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@chefhoobajoob](https://discuss.gradle.org/u/chefhoobajoob)\
**Post date:** [December 19, 2015, 5:23pm UTC](https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378/2 "2015-12-19T17:23:52Z")

</div>

Here is a workaround, if anybody’s run into the same problem:

```gradle
    tasks {
        export(Copy) {
            from( $.components.main.sources.cpp.getExportedHeaders() ) {
                into 'Include'
            }
            from( "$buildDir/libs/main" ) {
                into 'Lib'
            }
            into "$buildDir/export"
        }
        create('publishExports') {
            doLast {
                file("$buildDir/export/Include").renameTo(file("$projectDir/Include"))
                file("$buildDir/export/Lib").renameTo(file("$projectDir/Lib"))
            }
        }
        build.finalizedBy export
        export.finalizedBy publishExports
    }

```

---

<div class="post-metadata">

**Author:** ![chefhoobajoob](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@chefhoobajoob](https://discuss.gradle.org/u/chefhoobajoob)\
**Post date:** [January 8, 2016, 7:02pm UTC](https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378/3 "2016-01-08T19:02:23Z")

</div>

Any ideas on this? Is this a bug?

---

<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:** [January 8, 2016, 8:00pm UTC](https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378/4 "2016-01-08T20:00:06Z")

</div>

@lhotari, can you provide any insight here?

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [January 9, 2016, 1:26am UTC](https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378/5 "2016-01-09T01:26:05Z")

</div>

I think the issue is that by copying `into` the project directory you’re marking the entire project directory as a task output.

Before executing a Copy task, Gradle will check to see if the output directory contents have changed in any way since last time the task was executed. To do this, Gradle needs to take a snapshot of the directory and store it for next time: the value is stored under `$projectDir/.gradle`. You can see a problem there: in creating the directory snapshot Gradle is changing the snapshot. So even if you didn’t get this exception, you’d get strange behaviour with the task never being up to date.

Bottom line is that `$projectDir` should never be a Task input or output. For this example, one simple way to fix it is to have 2 separate `Copy` tasks:

```gradle
    tasks {
        exportInclude(Copy) {
            from $.components.main.sources.cpp.getExportedHeaders()
            into "$projectDir/Include"
        }
        exportLib(Copy) {
            from $.tasks.createMainReleaseStaticLibrary
            into "$projectDir/Lib"
        }
    }

```

---

<div class="post-metadata">

**Author:** ![chefhoobajoob](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@chefhoobajoob](https://discuss.gradle.org/u/chefhoobajoob)\
**Post date:** [January 9, 2016, 5:51pm UTC](https://discuss.gradle.org/t/2-10-rc2-copy-into-projectdir-fails/13378/6 "2016-01-09T17:51:12Z")

</div>

Ok - thank you for the clarification. The recommendation you make above for an alternative is where I ended up, so I guess it’s all good. Thanks!
