How to Store Secrets in a Gradle Project

Posted: 07 Jun 2022. Last modified on 08-Jun-22.

This article will take about 1 minute to read.


Part of the fun of writing code is having other people use it! But before making your code public, you should make sure that it does not contain any secrets.

Secrets are a very blanket term for anything that your app needs to be able to run, but which should not be public knowledge. Some examples include:

Where to store secrets

In a file that’s not checked into version control In an environment variable (which you can set in the config file for your shell of choice, either ~/.bashrc or ~/.zshrc)

# ~/.gradle/gradle.properties

https://github.com/google/secrets-gradle-plugin

https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties

https://tomgregory.com/gradle-project-properties-best-practices/#2As_Java_system_properties_using-D

https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package