错误“无法从 Groovy 闭包引用 Gradle 脚本对象,因为配置缓存不支持这些对象”

Error "Cannot reference a Gradle script object from a Groovy closure as these are not supported with the configuration cache"

提问人:Hong 提问时间:10/3/2023 更新时间:10/11/2023 访问量:188

问:

我创建了复制和 FTP 包的任务

task ftp(dependsOn: "copyApk") {
    doLast {
        ant {
            taskdef(name: 'ftp',
                    classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
                    classpath: configurations.ftpAntTask.asPath)
            ftp(server: "ftp.mydomain.com", userid: "ftp.mydomain.com|administrator", password: "adkjadfsid", remoteDir: "download") {
                fileset(dir: "E:/.../download/") {
                    include(name: "my-app.apk")
                }
            }
        }
    }
}

它完美地工作了几年。我最近将 Android Studio 升级到了 Giraffe 和许多其他软件包,包括 gradle。根据 Android Studio 的建议,该任务的脚本已更改为以下内容:

tasks.register('ftp') {
    dependsOn "copyApk"
    doLast {
        ant {
            taskdef(name: 'ftp',
                    classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
                    classpath: configurations.ftpAntTask.asPath)
            ftp(server: "ftp.mydomain.com", userid: "ftp.mydomain.com|administrator", password: "adkjadfsid", remoteDir: "download") {
                fileset(dir: "E:/.../download/") {
                    include(name: "my-app.apk")
                }
            }
        }
    }
}

当我运行任务时,我收到以下错误:

Cannot reference a Gradle script object from a Groovy closure as these are not supported with the configuration cache.

有问题的行是:

ant {

谁能提供关于如何解决这个问题的提示?

android-studio android-gradle-7.0 android-studio-girafee

评论


答:

1赞 Fhl 10/11/2023 #1

解决方法是,您可以在运行任务时禁用配置缓存。例如:

./gradlew ftp --no-configuration-cache