Colton Idle
01/15/2025, 4:00 PMThomas Broyer
01/15/2025, 4:08 PMColton Idle
01/15/2025, 4:10 PMColton Idle
01/15/2025, 4:12 PMColton Idle
01/15/2025, 4:12 PMThomas Broyer
01/15/2025, 5:03 PMColton Idle
01/15/2025, 7:03 PMtasks.register("getCommitMessages") {
             doLast {
                 println("print release notes")
            ...
             }
}ANDROID_KEYSTORE_FILEPATHANDROID_KEYSTORE_FILEPATHThomas Broyer
01/15/2025, 7:16 PMColton Idle
01/15/2025, 7:42 PMsigningConfigs {
         create("release") {
             storeFile = file(System.getenv(["ANDROID_KEYSTORE_FILEPATH"])
             storePassword = "password"
             keyAlias = "staging"
             keyPassword = "password"
         }
     }Colton Idle
01/15/2025, 7:43 PMChris Lee
01/15/2025, 7:44 PMlazyColton Idle
01/15/2025, 7:46 PMThomas Broyer
01/15/2025, 7:46 PMregister("release")create("release")create()register()Chris Lee
01/15/2025, 7:46 PMGradle provides a number of environment variables, which are listed below. Environment variables can be retrieved lazily using.providers.environmentVariable()
Chris Lee
01/15/2025, 7:47 PMSystem.getenvColton Idle
01/15/2025, 7:47 PMColton Idle
01/15/2025, 7:49 PMColton Idle
01/15/2025, 7:50 PMChris Lee
01/15/2025, 7:50 PMChris Lee
01/15/2025, 7:51 PMPlugins and build scripts may read system properties and environment variables directly at configuration time with standard Java, Groovy, or Kotlin APIs or with the value supplier APIs. Doing so makes such variable or property a build configuration input, so changing the value invalidates the configuration cache. The configuration cache report includes a list of these build configuration inputs to help track them.
In general, you should avoid reading the value of system properties and environment variables at configuration time, to avoid cache misses when value changes. Instead, you can connect the `Provider`returned by providers.systemProperty() or providers.environmentVariable() to task properties.https://docs.gradle.org/current/userguide/configuration_cache.html
Chris Lee
01/15/2025, 7:52 PMColton Idle
01/15/2025, 7:54 PMsomething else got adjusted in translation to make the resolution eager. Its often hard to tell from Groovy what actual API call happens on the backend, so translating one-to-one can be challenging.interesting. i will take another look, but thats actually exactly what i was looking for. that it was always eager and its not just a groovy vs kts thing
Colton Idle
01/15/2025, 7:54 PMChris Lee
01/15/2025, 7:59 PMprintlnephemient
01/16/2025, 5:09 AMSystem.getenvephemient
01/16/2025, 5:11 AMproviders.environmentVariableephemient
01/16/2025, 5:20 AMsigningConfigs {
    create("release") {
        val storeFilePath = System.getenv("ANDROID_KEYSTORE_FILEPATH")
        if (storeFilePath.isNullOrEmpty()) return@create
        storeFile = file(storeFilePath)
        storePassword = "password"
        keyAlias = "staging"
        keyPassword = "password"
    }
}Colton Idle
01/16/2025, 5:32 AMoooh. interesting. so i can't actually usereturns a nullable string, but it's possible that Kotlin is enforcing nullability checking on APIs where Groovy does notSystem.getenv
providers.environmentVariableephemient
01/16/2025, 8:00 AMColton Idle
01/16/2025, 9:11 PMVampire
01/16/2025, 11:38 PMfor a second i thought maybe kts precompiles things or something since its "static" vs dynamic "groovy"That's actually irrelevant. Yes, Kotlin code needs to be compiled of course. I think - but am not sure right now - the Groovy code is also compiled, so that it does not need to be interpreted each time it is run if it did not change. But whether you compile it or not before you run it is irrelevant.
System.getenv(...)tasks.foo {
   ...
}oooh. interesting. so i can't actually useSure you can, just does not make much sense if you need the configuration at configuration time because the property you configure is not a lazy Gradle property. If what you configure there is a https://developer.android.com/reference/tools/gradle-api/8.3/com/android/build/api/dsl/SigningConfig, then thein android signing?providers.environmentVariable
storeFileFileSystem.envproviders.environmentVariableThat signing configs block exists inside of the android block. while the tasks.register exists inside of the buildTypes block, which is inside of the android block.The block you showed will not even compile in Kotlin. In Groovy it will compile but fail at runtime as
ArrayListStringreleasecreateSystem.getenvColton Idle
01/21/2025, 5:20 AMephemient
01/21/2025, 6:04 AMreturns a nullable string, but it's possible that Kotlin is enforcing nullability checking on APIs where Groovy does notSystem.getenv
ephemient
01/21/2025, 6:04 AMfile()ephemient
01/21/2025, 6:05 AM"null"ephemient
01/21/2025, 6:07 AMstoreFile = file("${System.getenv("KEYSTORE_FILE")}")storeFile = file(System.getenv("KEYSTORE_FILE").toString())System.getenv("KEYSTORE_FILE")?.let { storeFile = file(it) }storeFile = System.getenv("KEYSTORE_FILE")?.let(::file)Vampire
01/21/2025, 8:50 AMFile("release.txt")new File("release.txt")FileFileInputStreamColton Idle
01/21/2025, 1:39 PMephemient
01/21/2025, 1:43 PMColton Idle
01/21/2025, 3:44 PMfun getProperty(propertyName: String) : String {
  val prop = project.properties[propertyName]
    ?: gradleLocalProperties(rootDir, providers).getProperty(propertyName)
    ?: System.getenv()[propertyName]
    ?: throw IllegalStateException("Add a local property or env variable")
return prop
}Chris Lee
01/21/2025, 3:48 PMfile("${System.getenv("KEYSTORE_FILE")}")file("null")Thomas Broyer
01/21/2025, 5:30 PMfile(System.env.KEYSTORE_FILE)System.get("KEYSTORE_FILE")?.let(::file)Colton Idle
01/21/2025, 5:47 PM