GoogleCloudPlatform / app-gradle-plugin

The library has moved to https://github.com/GoogleCloudPlatform/appengine-plugins/tree/main/app-gradle-plugin
Apache License 2.0
153 stars 40 forks source link

Support for build variants similiar to Android #83

Closed Burtan closed 7 years ago

loosebazooka commented 7 years ago

Can you be more specific, what exactly are you trying to customize?

Burtan commented 7 years ago

At the moment I have two flavours of one service. One flavour is the sandbox, the other one is the production environment. I have one class with constants which I comment out depending on which flavour I want to publish. The constants contain API information like URL and client IDs.

Burtan commented 7 years ago

A good point to start with would be defined properties similar to BuildConfig with Android. I think some of the sample projects using Maven use properties, but I didn't find a way to do so with gradle.

loosebazooka commented 7 years ago

This seems like something that can be solved by gradle and isn't appengine specific. Android has defined a convention for doing that for Android projects and within the IDE, but it doesn't make sense for us to provide such a strong suggestion to app engine developers.

A way to mimic that behavior would be to do it on your own. Perhaps by controlling the sourceset includes?

Something like (I don't know if this will actually work, but you could play around with it, there are probably other ways to do this too) :

sourceSets {
  main {
    java {
      if ( /*some condition for debug*/ ) {
        srcDirs "src/variants/debug/java"
      }
      else if ( /*some condition for prod*/) {
        srcDirs "src/variants/prod/java"
      }
    }
  }
}

And here some condition can be checking a system or gradle property or something like that.

./gradlew assemble -Pvariant=debug

It's really up to you.

Burtan commented 7 years ago

Thanks, I'll look into it.