Gradle 在命令行中传递渐变任务参数

Gradle 在命令行中传递渐变任务参数,gradle,intellij-idea,groovy,cmd,task,Gradle,Intellij Idea,Groovy,Cmd,Task,我试图找到从命令行传递gradle任务参数的最佳方法。 我有这个任务。我想将学生练习中的答案解包出来,并将它们复制到项目中正确的位置,以评估它们。我这样称呼这个任务: > gradle swapSolution -Pstudent=MyStudent -Pexercise=ex05 在启用Gradle插件时,我在IntelliJ中执行此操作时遇到的一个问题是,我在构建项目时收到此错误消息。解决这个问题的办法是什么 A problem occurred evaluating root pr

我试图找到从命令行传递gradle任务参数的最佳方法。 我有这个任务。我想将学生练习中的答案解包出来,并将它们复制到项目中正确的位置,以评估它们。我这样称呼这个任务:

> gradle swapSolution -Pstudent=MyStudent -Pexercise=ex05
在启用Gradle插件时,我在IntelliJ中执行此操作时遇到的一个问题是,我在构建项目时收到此错误消息。解决这个问题的办法是什么

A problem occurred evaluating root project 'kprog-2020-ws'.
> Could not get unknown property 'student' for root project 'kprog-2020-ws' of type org.gradle.api.Project.
这是gradle的任务:

task swapSolution(type: Copy) {
    new File("${rootDir}/Abgaben").eachDir { file ->
        if (file.name.toString().matches("(.*)" + project.property("student") + "(.*)")) {
            def exDir = new File("/src/main/java/prog/" + project.property("exercise"))
            if (!exDir.exists()) {
                delete exDir
            }
            new File(file.path).eachFile { zipSolution ->
                //def zipFile = new File("./Abgaben/" + file.name.toString() + "/" + project.property("exercise") + "Solution.zip")
                from zipTree(zipSolution)
                into "/src/main/java/"
            }

        }
    }
}
你对优化这个过程有什么建议吗?

-p
梯度。如果需要使用项目属性,可以将其指定为项目根目录中的
gradle.properties
文件

如果您的任务类型为
JavaExec
,则可以使用
--args
开关,并将其传递到Together的Arguments文本字段中,并使用任务名称,如
swapSolution-args=“-student=MyStudent-exercise=ex05”
。另见

非常感谢您的回复,这对我理解程序有很大帮助。解决我的问题的方法是,我现在使用system.getProperties().get(“学生”),而不是像这个system.properties(“学生”)那样使用系统属性student。这种方式评估项目不会在不知道参数的情况下崩溃。非常感谢。