secrets-gradle-plugin icon indicating copy to clipboard operation
secrets-gradle-plugin copied to clipboard

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

Open arohim opened this issue 2 years ago • 4 comments

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?

arohim avatar Aug 17 '21 04:08 arohim

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

arriolac avatar Aug 17 '21 20:08 arriolac

I see, thank you for letting me know

arohim avatar Aug 24 '21 07:08 arohim

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

saket avatar Mar 27 '22 17:03 saket

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)
    }
}

saeedata avatar Sep 03 '22 09:09 saeedata