Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Latest commit

 

History

History
70 lines (56 loc) · 2.59 KB

README.md

File metadata and controls

70 lines (56 loc) · 2.59 KB

gradle-build-properties-plugin

Bintray

External properties support for your gradle builds.

Description

Gradle builds are highly configurable through various properties. Rather than hardcoding these properties in your build scripts, for security reasons and in order to increase modularity, it's a common practice to provide these properties from external sources.

This plugin aims to provide a simple way to:

  • consume properties from external and internal sources like project properties, system properties, files etc.
  • define a custom source for properties
  • configure Android build with external properties

Adding to your project

The plugin is deployed to Bintray's JCenter. Ensure it's correctly defined as a dependency for your build script:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.novoda:gradle-build-properties-plugin:0.3'
  }
}

Then apply the plugin in your build script via:

apply plugin: 'com.novoda.build-properties'

Simple usage

Add a buildProperties configuration to your build script listing all the properties files you intend to reference later on:

buildProperties {
    
    secrets {
        using project.file('secrets.properties')
    }
}

where secrets.properties is a properties file, containing key/value pairs, that can now be referenced in the build script as buildProperties.secrets:

boolean enabled = buildProperties.secrets['a'].boolean
int count = buildProperties.secrets['b'].int
double rate = buildProperties.secrets['c'].double
String label = buildProperties.secrets['d'].string

It is important to note that values are lazy loaded too. Trying to access the value of a specific property could generate an exception if the key is missing in the provided properties file, eg:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> No value defined for property 'notThere' in 'secrets' properties (/Users/toto/novoda/spikes/BuildPropertiesPlugin/sample/properties/secrets.properties)

Advanced usage

For more advanced configurations, please refer to the advanced usage.