gradle from("originPath") and into("targetPath") 如何以及为什么删除文件?
How and why does gradle from("originPath") and into("targetPath") delete's files?
我有一个 gradle 任务,它需要一个目录并将其复制到另一个目录。
from({ framework.outputDirectory }) into(File("/Users/user/Desktop/"))
此处已满gradle.kts任务
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/"))
}
我认为它只会将 framework.outputDirectory
复制到 Desktop
,但是当我 运行 该任务时它删除了我在桌面上的所有文件(包括一些未备份的项目)。我无法恢复这些文件。
问题: 为什么gradle into
删除了文件?它是否每次都创建新文件夹并覆盖所有内容?
您的任务不是 Copy
类型,而是 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.
我有一个 gradle 任务,它需要一个目录并将其复制到另一个目录。
from({ framework.outputDirectory }) into(File("/Users/user/Desktop/"))
此处已满gradle.kts任务
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/"))
}
我认为它只会将 framework.outputDirectory
复制到 Desktop
,但是当我 运行 该任务时它删除了我在桌面上的所有文件(包括一些未备份的项目)。我无法恢复这些文件。
问题: 为什么gradle into
删除了文件?它是否每次都创建新文件夹并覆盖所有内容?
您的任务不是 Copy
类型,而是 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 apreserve(Action)
is specified.