This is more of a Compose Desktop Gradle-level que...
# compose-desktop
v
This is more of a Compose Desktop Gradle-level question — How to include secrets (like API keys) in a Compose-Desktop project without committing to Git? For example, we have
buildConfigField()
in build.gradle in Android projects, which generates the BuildConfig.java file, and that can be used during runtime. Is there a similar approach in Compose Desktop projects so that I can add secrets as System Env variable (or even a git-ignored properties file) and don't have to commit it? I added a question on StackOverflow just now: https://stackoverflow.com/questions/71002334/compose-desktop-projects-how-to-include-api-keys-or-other-secrets-without-com
s
answered on stackoverflow.
👍🏻 1
👍 1
v
Both the plugins you suggested is exactly doing what I wanted. As you said, messing around with third-party plugin can be a problem, and let me wait and see if anyone has solved this without plugins. The shell script is a good idea, but that has to be configured in Gradle to execute every time we do a
build
or
run
task, otherwise we have to run it manually.
s
No - you would only run the shell script in CI. Whatever the contents of the file are initially should work for your dev experience
i.e. your defaults could be to read the values from a file that isn’t checked into git.
v
Oh oh I get it now. So in my local machine, need to run it again only if I am switching to another set of secrets. That looks a good idea.
c
I didn't read the SO question, but in general I think the same general rules apply. You can just put secrets in an environment variable and call it a day. There are some plugins and such that can help depending on the build system, but almost every project I've used just defaults to putting things in env vars.
v
Yes, I wanted to use environment variables, but didn't know how to bring them into the Kotlin sources during compile time. I used a plugin and it works like a charm👌 https://github.com/gmazzo/gradle-buildconfig-plugin The Android Gradle Plugin comes with the
buildConfig
feature, so I was checking if there's a similar option comes built-in for Compose Desktop projects.