如何创建动态设置App Engine项目ID并运行appengineDeploy任务的任务?

在此示例中,当我运行deployStagingappengineDeploy与项目“a”一起执行时,如何重写此代码以使其与项目“b”一起运行?

buildscript {
    dependencies {
        classpath("com.google.cloud.tools:appengine-gradle-plugin:2.0.1")
    }
}
apply plugin: 'com.google.cloud.tools.appengine'

def gcpProject = 'a'

appengine {
    deploy {
        projectId = gcpProject
    }
}

task deployStaging() {
    doLast {
        gcpProject = 'b'
    }
}
deployStaging.finalizedBy appengineDeploy

最佳答案

改用project property怎么样?可以通过-P命令行参数传递项目属性:

buildscript {
    dependencies {
        classpath("com.google.cloud.tools:appengine-gradle-plugin:2.0.1")
    }
}
apply plugin: 'com.google.cloud.tools.appengine'

def gcpProject = project.findProperty('stageName') ?: 'a'

appengine {
    deploy {
        projectId = gcpProject
    }
}

现在,如果您仅调用./gradlew appengineDeploy,则gcpProject变量将具有值'a'。如果调用./gradlew appengineDeploy -PstageName=b,则gcpProject变量的值将为'b'。

关于google-app-engine - 如何动态设置AppEngine Gradle属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56564454/

10-09 06:17