Abduelrahman Elemam
09/30/2024, 12:24 PMlocal.properties
and .env
files with System.getenv("Var Name")
, but unfortunately, these attempts always return null.
Currently, the only reliable approach seems to be storing sensitive variables directly in the gradle.properties
file. However, this means the secrets would be uploaded to Git, which I'd like to avoid for security reasons.
Does anyone have any alternative solutions that would allow me to securely store sensitive variables outside of gradle.properties
and access them within my KMP Gradle file?Michael Krussel
09/30/2024, 12:30 PMgradle.properties
to avoid having it get uploaded to Git.
For local.properties
you need to manually load the properties file it doesn't get auto loaded like gradle.properties
.Abduelrahman Elemam
09/30/2024, 12:32 PMgradle-secrets-plugin.properties
and added these vars there and it also the same.
is this requires to manually load the file also ??Abduelrahman Elemam
09/30/2024, 12:33 PMin their user home
? in the root project ?Azim Ansari
09/30/2024, 12:36 PMlocal.properties
should work for you without nulls, if you are loading it correctly.
Use below code
val localProperties = Properties()
val localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
localPropertiesFile.inputStream().use { stream ->
localProperties.load(stream)
}
}
Abduelrahman Elemam
09/30/2024, 12:40 PMMichael Krussel
09/30/2024, 12:58 PM~/.gradle/gradle.properties
is visible to all projects.
https://docs.gradle.org/current/userguide/build_environment.html#priority_for_configurationsephemient
09/30/2024, 1:03 PMprivate abstract class PropertiesFileValueSource : ValueSource<Properties, PropertiesFileValueSource.Parameters> {
interface Parameters : ValueSourceParameters {
val propertiesFile: RegularFileProperty
}
override fun obtain(): Properties = Properties().apply {
parameters.propertiesFile.get().asFile.inputStream().use { load(it) }
}
}
val localProperties = providers.of(PropertiesFileValueSource::class) {
parameters.propertiesFile = rootProject.file("local.properties")
}
which would then be lazily loaded and tracked by GradleAbduelrahman Elemam
09/30/2024, 1:40 PMAbduelrahman Elemam
09/30/2024, 1:41 PM