GoogleCloudPlatform / app-gradle-plugin

The library has moved to https://github.com/GoogleCloudPlatform/appengine-plugins/tree/main/app-gradle-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to dynamically set appengine gradle property

ivorcosta opened this issue · comments

How can I create a task that dynamically set app engine project id and run the appengineDeploy task?

On the following example when I run deployStaging appengineDeploy is being executed with project 'a', how I can rewrite this code to make it run with project 'b'?

This link shows one example of solving this problem using project property. The only detail is that I will have to edit intellij to run the task with parameters, I would like to have one task with the parameters already configured. Is there a easy/elegant solution for this? Or I should forget, carry on my life and use the above link solution?

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
commented

Can you explain exactly what you're trying to do? In your sample code, the problem doesn't really make sense to me (there's no reason to dynamically adjust the project).

I'm trying to create one "helper task" that will deploy my code into a specific environment. For example:

task deployStaging // will deploy on project my-project-staging
task deployProduction // will deploy on project my-project-production
commented

I think the link you suggest is actually the correct way to do it. But, you can get kind of messy with gradle (which I don't recommend) but you can decide if that's what you want. There are many drawbacks to this method, but it does solve your clicking on a task in intellij problem.

appengine {
  deploy {
     version = "123"
     // do not define projectId here
  }
}

task deployStaging {
  dependsOn appengineDeploy
}
task deployProduction {
  dependsOn appengineDeploy
}

// here's the weird gradle logic, use at your own risk
if (project.gradle.startParameter.taskNames.contains("deployStaging")) {
  appengine.deploy.projectId = "potato-stage"
}
else if(project.gradle.startParameters.tasksNames.contains("deployProduction")) {
  appengine.deploy.projectId = "tomato-prod"
}

Tks for the reply, it is indeed a bit strange. I will check with the team which approach they prefer.