gpt4 book ai didi

gradle - Gradle-每个的命令行

转载 作者:行者123 更新时间:2023-12-03 05:07:02 28 4
gpt4 key购买 nike

我有以下代码,但configFilesPath行中仅调用了commandLine的最后一项。

任何想法我应该使用什么-以便它为configFilesPath中的每个项目运行commandLine?

@TaskAction
fun create() {
project.exec({
workingDir(project.projectDir)

var configFilesPath = Paths.get(System.getProperty("user.dir"), "../../../", "myconfig/");
//Create symlinks for all files in myconfig/
Files.list(configFilesPath).forEach{
val configFile = configFilesPath.toString() + "/" + it.fileName
commandLine("ln", "-s", configFile)
}
})

}

谢谢。

最佳答案

参见ExecSpec:当您编写commandLine("ln", "-s", configFile)时,您实际上是在调用commandLine属性setter;如果将此调用包装在forEach循环中,则将仅使用最后一个值(这是您观察到的)。实际上,Exec任务只能具有一个commandLine

在您的情况下,您可以将project.exec( {...})调用包装到forEach块中,以便为每个配置文件触发一个exec调用。

这样的事情应该起作用(代码未经测试,您可能需要稍作修改):

@TaskAction
fun create() {

var configFilesPath = Paths.get(System.getProperty("user.dir"), "../../../", "myconfig/");
// Iterate over all files in myconfig/
Files.list(configFilesPath).forEach{
val configFile = configFilesPath.toString() + "/" + it.fileName
project.exec({
workingDir(project.projectDir)
commandLine("ln", "-s", configFile)
})
}
}

注意,您还应该在 doLast { }块中配置任务。

关于gradle - Gradle-每个的命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56554423/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com