Search code examples
gradlegroovygradle-kotlin-dslkotlin-multiplatform-mobile

How and why does gradle from("originPath") and into("targetPath") delete's files?


I have a gradle task, which takes one directory and copies it into another directory.

from({ framework.outputDirectory }) into(File("/Users/user/Desktop/"))

here is full gradle.kts task

val generateIOSArm64Framework by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "iosArm64"
    val framework =
        kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    from({ framework.outputDirectory })
    into(File("/Users/user/Desktop/"))
}

I thought it will just copy's framework.outputDirectory into Desktop, but when I run that task it deleted all my files which were on Desktop (including some non backuped project). I can't restore those files.

Question: why gradle into delete's files? does it creates new folder every time and override's everything?


Solution

  • Your task is not of type Copy but of type Sync:

    This task is like the Copy task, except the destination directory will only contain the files copied. All files that exist in the destination directory will be deleted before copying files, unless a preserve(Action) is specified.