access environment variables inside buildscript {..} closure

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

access environment variables inside buildscript {..} closure

tuhin
This post has NOT been accepted by the mailing list yet.
Hi All,

I would like to access some environment variables inside buildscript {..} closure, so that I can set some more variables based on that, and then use them to resolve my dependancies.
I keep my PROD dependancy stuff under release repo, and the Test version of those stuff under snapshot repo.

I am trying to comeup with a single build.gradle file, which I should be calling with a -Denv switch, for "prod" or "test" , and based on that the dependacies will be downloaded and resolved.

Some thing like:

buildscript {
  repositories {
    maven {
      name 'release'
      url "XXSomeReleaseRepoXX"
    }
    maven {
      name 'snapshot'
      url "XXSomeSnapshotRepoXX"
    }
  }

environment = System.properties["env"]  
if (environment == "prod") {
   version = "1.0"
} else {
   version = "1.0-SNAPSHOT"
}
   dependencies {
    classpath "com.XXX:ABC:${version}+"
    classpath "com.XXX:ABC:${version}+"    
   }
}

Is this kind of configuration supported inside buildscript {...} closure since buildscript gets the special treatment and gets processed as soon as the script is loaded?

I am receiving errors suggesting me that neither the properties nor the variable exist for this closure or the rootProject configuration!!

Thanks in advace for help.

Regards,
Tuhin Mohanta
Reply | Threaded
Open this post in threaded view
|

Re: access environment variables inside buildscript {..} closure

rnavarette
This post has NOT been accepted by the mailing list yet.
You're looking for System.getenv("MY_ENV_VAR"), not System.properties.