google / secrets-gradle-plugin

A Gradle plugin for providing your secrets to your Android project.
Apache License 2.0
1.13k stars 99 forks source link

The plugin is ignoring my custom file when specific the file with path. #39

Open arohim opened 3 years ago

arohim commented 3 years ago

As the document said we have to create a custom file at the root of the folder and it's working fine on my project, Is it possible to move my custom file into another folder?

staging {
    secrets {
        propertiesFileName 'properties/staging.properties'
    }
}

The plugin is ignoring my custom file with the path and then somehow read from my release.properties instead.

Does anyone know how to read the configuration file from another folder?

arriolac commented 3 years ago

Reading from another folder is not possible at the moment. If this is useful for others as well it can certainly be implemented.

arohim commented 3 years ago

I see, thank you for letting me know

saket commented 2 years ago

It'd be nice to have this. I am trying to use this plugin in multiple modules with a single properties file.

saeedata commented 2 years ago

hi, I have this issue too, you can clone the project and use it locally with these changes:

instead of getting root project in SecretsPlugin.kt file:

project.rootProject.loadPropertiesFile(
        extension.propertiesFileName
)

you can change to:

project.loadPropertiesFile(
       extension.propertiesFileName
)

this change load properties from current module: however you should be aware about how the plugin work, I mean if you don't declare a file path in the plugin extension config for properties, you should at least have local.properties file in any module you want to use plugin or maybe you can change this logic as well.

const val defaultPropertiesFile = "local.properties"

also I'd like to have a regex for properties files, so you can change this line too:

val buildTypeFileName = "secrets.${variant.buildType}.properties"
val flavorFileName = "secrets.${variant.flavorName}.properties"

this force the properties files to start with secrets.

in addition, if you like to have boolean and integer variable in you BuildConfig too you can change these line too:

fun Variant.inject(properties: Properties, ignore: List<String>) {
   val ignoreRegexs = ignore.map { Regex(pattern = it) }
   properties.keys.map { key ->
        key as String
    }.filter { key ->
        key.isNotEmpty() && !ignoreRegexs.any { it.containsMatchIn(key) }
    }.forEach { key ->
        val value = properties.getProperty(key).removeSurrounding("\"")
        val translatedKey = key.replace(javaVarRegexp, "")
        if (value == "true" || value == "false") {
            buildConfigFields.put(
                translatedKey,
                BuildConfigField("boolean", value, null)
            )
        } else if (value.matches("\\d+(?:\\.\\d+)?".toRegex())) {
            buildConfigFields.put(
                translatedKey,
                BuildConfigField("int", value, null)
            )
        } else {
            buildConfigFields.put(
                translatedKey,
                BuildConfigField("String", value.addParenthesisIfNeeded(), null)
            )
        }
        manifestPlaceholders.put(translatedKey, value)
    }
}