/* This Gradle script provides a way to load values from a Json file into the project properties. Properties are named with the key value from the Json, and the value is the json value. */ import groovy.json.JsonSlurper // Loads secrets using a secrets.json file or a file path specified by the environment. def loadSecrets() { final def secretFile = file System.getenv('SECRET_FILE') ?: 'secrets.json' loadSecrets(secretFile) } // Loads secrets using a specified json file. def loadSecrets(secretFile) { if (secretFile.exists()) { secretFile.withReader { Map secretMap = new JsonSlurper().parse it for (entry in secretMap) { project.ext.set(entry.key, entry.value) } project.logger.info('Successfully loaded ' + secretMap.size() + ' secret properties') } } else { project.logger.warn('The secret file ' + secretFile.getName() + ' could not be loaded. It does not exist.') } } // This allows other projects to use these methods. ext { loadSecrets = this.&loadSecrets }