'Compose Desktop projects: how to include API keys (or other secrets) without committing?

In Compose Desktop projects, how can we manage secret keys without committing?

In Android projects, Gradle has the buildConfigField() and resValue() functions. They will generate a BuildConfig.java during compile time, and we can use the values during runtime.

For example, in an Android project, first, we create two environment variables — RELEASE_API_KEY and STAGING_API_KEY (It can be either local computer, or a CI/CD environment).

Then in build.gradle file we can say:

android {
   buildTypes {
     release {
       buildConfigField("String", "API_KEY", "\"${System.getenv('RELEASE_API_KEY')}\"")
     }
     staging {
       buildConfigField("String", "API_KEY", "\"{System.getenv('STAGING_API_KEY')}\"")
     }
   }
}

..and in the Kotlin code we can use:

val apiManager = ApiManager( BuildConfig.API_KEY )

Is there a similar approach in Compose Desktop projects so that:

  1. I don't have to commit the secret to the source repository?
  2. I can easily configure secrets in a CI/CD environment?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source