Gradle找不到参数的方法XYZ。

Gradle找不到参数的方法XYZ。,gradle,Gradle,Gradle和Groovy尝试使用以下任务时有点陌生: 如下: task pushImageDev(type: DockerPushImage) { imageName "xxxxxx:5000/${project.name}-${appEnviroment}:${version}" registryCredentials { email = 'none@your.business' url = 'xxxxxx:5000' use

Gradle和Groovy尝试使用以下任务时有点陌生:

如下:

task pushImageDev(type: DockerPushImage) {
    imageName "xxxxxx:5000/${project.name}-${appEnviroment}:${version}"

    registryCredentials {
        email = 'none@your.business'
        url = 'xxxxxx:5000'
        username =  'xxxxxx'
        password =  'xxxxxx'
    }
}
但是我一直

Could not find method registryCredentials() for arguments [build_21ymvy7kfomjn3daqwpuika10$_run_closure8$_closure18@dd69c19] on task ':pushImageDev' of type com.bmuschko.gradle.docker.tasks.image.DockerPushImage

我相信您只能在
docker
任务配置中使用
registryCredentials
方法,而不能在自定义任务中使用,如

docker {
    registryCredentials {
        url = 'https://gcr.io'
        username = '_json_key'
        password = file('keyfile.json").text
    }
}
如果要创建自定义任务,可能必须创建DockerRegistryCredentials的实际实例才能传递,如

task pushImageDev(type: DockerPushImage) {
    imageName "xxxxxx:5000/${project.name}-${appEnviroment}:${version}"

    registryCredentials(new DockerRegistryCredentials(...));
}
原因是,
registryCredentials{…}
是中定义的扩展,不适用于自定义任务。它不是类
DockerPushImage
内部的字段
registryCredentials
的设置器

同样有效的方法是在自定义任务中的
docker
调用中嵌套注册表凭据调用,尽管我不确定原因:

task pushImageDev(type: DockerPushImage) {
    appEnviroment = 'dev'
    imageName "xxxxxx/${project.name}-${appEnviroment}:${version}"

    docker {
        registryCredentials {
            username = "${nexusUsername}"
            password = "${nexusPassword}"
        }
    }
}

好的,检查问题。:)正如我是作者所解释的,我想包括那个可行的替代方案。