Git Product home page Git Product logo

gradle-build-properties-plugin's Introduction

๐Ÿ›‘ THIS REPOSITORY IS OFFICIALLY NO LONGER UNDER MAINTENANCE since 10/02/2022 ๐Ÿ›‘

gradle-build-properties-plugin

Bintray

External properties support for your gradle builds.

Using the old com.novoda:build-properties-plugin? You should migrate away from it as soon as possible.

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

Apply the plugin from jCenter as a classpath dependency:

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

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

or from the Gradle Plugins Repository:

plugins {
    id 'com.novoda.build-properties' version '0.4.1'
}

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:

secret_key=12345
foo=bar

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, e.g.:

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.

gradle-build-properties-plugin's People

Contributors

ataulm avatar devisnik avatar frapontillo avatar iturricf avatar jozefceluch avatar juankysoriano avatar lgvalle avatar mr-archano avatar ouchadam avatar rock3r avatar takecare avatar tasomaniac avatar tobiasheine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gradle-build-properties-plugin's Issues

Remove built-in `buildProperties.env`, expose utility instead

At the moment the plugin introduce a set of build properties backed by system environment variables, eg:

buildProperties.env['JAVA_HOME']

Altho this has been proved to be useful I would prefer to let the user decide whether to define an entry in the buildProperties container and just expose a simple way of creating an instance of Entries from System.getnv() (or a map in general!).

Declare presence of signing properties optional

I do not want to require the presence of the releaseSigning.properties for my open source project in order to allow contributors to start using the project as quick as possible.

Currently, I am simply setting android.buildTypes.release.signingConfig to null as shown below:

File propFile = file("releaseSigning.properties");
if (propFile.exists()) {
    def Properties props = new Properties()
    props.load(new FileInputStream(propFile))

    if (props.containsKey("storeFile") &&
            props.containsKey("storePassword") &&
            props.containsKey("keyAlias") &&
            props.containsKey("keyPassword")
    ) {
        android.signingConfigs.release.storeFile = file(props["storeFile"])
        android.signingConfigs.release.storePassword = props["storePassword"]
        android.signingConfigs.release.keyAlias = props["keyAlias"]
        android.signingConfigs.release.keyPassword = props["keyPassword"]
    } else {
        android.buildTypes.release.signingConfig = null
    }
} else {
    android.buildTypes.release.signingConfig = null
}

How can I do the same with the gradle-build-properties-plugin?

Provide api to check whether entries contain a given key

Currently it's kinda hard to check whether the Entries contain a certain key.

Possible workarounds are:

if (buildProperties.cli['key'].or('none').string != 'none') {
   ...
}

or

buildProperties.cli.keys.toList().contains('key')

But ideally we would expose BuildProperties.contains(String key):

if (buildProperties.cli.contains('key')) {
   ...
}

Remove support for Android `signingConfig`

The support to Android signingConfig wasn't initially planned and added as last minute feature. This also forced some API in Entries that is not used in the standard scenarios (ie: Entries#getParentFile()).

Possibility to read properties file passed in command line

It is very common situation that you have application.properties file, but on specific environment you must override it (take --spring.config.location=file://override.properties as an example).

It would be great if gradle-build-properties-plugin would support overriding properties from the command line too

Missing readme example

More on loading properties

If the specified file is not found an exception is thrown at build time as soon as one of its properties is evaluated. You can specify a custom error message to provide the user with more information.

An example of this is missing from the readme

Support for yaml

Yaml is very popular format although it seems to not be supported by gradle-build-properties-plugin.
On the other hand, your plugin is awesome and I don't to stop using it, therefore I must stick to .properties format
Would you consider supporting yaml format as well?

Create migration documentation

When moving from the old coordinates (com.novoda:build-properties-plugin:1.2.1) to the new ones (com.novoda:gradle-build-properties-plugin:0.3.9), there are significant hurdles to overcome. We should have a migration guide on what's changed so it's easier for people to migrate.

Android Studio 2.2 Could not find method buildConfigString() for arguments

I've updated my build.gradle file to include gradle-build-properties-plugin. Then I tried to load some secrets into my debug buildType and got this message:

Error:(46, 0) Could not find method buildConfigString() for arguments [MY_SECRET_KEY, com.novoda.buildproperties.Entry@249d2bfe] on BuildType_Decorated{name=debug, debuggable=true, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, minifyEnabled=false, zipAlignEnabled=true}, embedMicroApp=false, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.BuildType

Is anything that I'm doing wrong?

my build.gradle file:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.22.1'
        classpath 'com.novoda:gradle-build-properties-plugin:0.3'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.novoda.build-properties'

...

android {
...

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

    buildTypes {
        debug {
            buildConfigString "MY_SECRET_KEY", buildProperties.secrets['a_secret_key'].or(buildProperties.env['MY_SECRET_KEY'])
       }
    }
...

Remove `include` support for `FilePropertiesEntries`

Following the discussion in #27:

I am also planning of removing this mechanism because not too flexible (relative paths provided by include property are now evaluated using the properties file parent folder as base). I really want to put in place something more explicit, [...] but embracing the inheritance of build properties holistically

buildProperties {
   default {
        from project.file('default.properties')
    }
    production {
        from project.file('production.properties')
        include 'default'
    }
}

Unexpected fallback entries failure

Hi there,

After defining a fallback file source, my build immediately fails when the first file the plugin goes looking for does not exist. Have I misunderstood the purpose of fallback entries?

The following is my exact use case:

buildProperties {
    secrets {
        using(file("non-existent.file")).or(file("guaranteed-to-exist.file"))
    }
}

My expectation from the documentation is that if the plugin does not find "non-existent.file", it will load (or attempt to load) "guaranteed-to-exist.file". But, assuming I've debugged correctly, it hits an immediate FileNotFound exception.

Is this intentional behavior?

For reference, I am using version 0.4.1 taken from the Gradle Plugins Repository.

Groovydoc is not being deployed

We used to generate Groovydoc with every release and showcase it at the following URL but there is an issue with the deployment: https://novoda.github.io/gradle-build-properties-plugin/docs/<VERSION>

Split `README` in multiple files

The README as it is now is very long and quite confusing. A new user should just be able to glance at it and understand how to use the plugin. Anything else can be covered as separate documentation (separate markdown documents in the repo).

Entries should provide Map interface

Different Entries implementations either use Map or Properties.
Properties already implement Map. Instead of having custom map like methods in Entries it should really be just extending Map.

Thanks to this change, the plugin will be easier to use thanks to already available map extensions in groovy.
Example: We can just use buildProperties.secrets.values() to access all values.

Add utility to create `Entries` from project properties

In a couple of projects using this plugin we already have scripted another implementation of Entries backed by project or system properties. This is particularly handy to pass parameters via cli to override values defined in properties files.

or support for signing configs

I was experimenting with the plugin on the weekend.
or support works great for missing or optional prop files. But the signing configs does not support it.

When my project is cloned, I want it to be immediately buildable. At least the debug build.

So I fiddled with the plugin and added or support to the file method in BuildProperties. It worked quite well. I could go like this

    releaseSigning {
        file file('properties/releaseSigning.properties')
        or file('properties/debugSigning.properties')
    }

But I realized, it may not be really something we want. Comparing it with include and or support on Entity, it is only necessary for signing configs.

So I'm thinking about working on addSigningConfigSupportTo to support alternatives configs if not found.

What do you think?

Remove `buildConfigProperty` and `resValueProperty`

At the moment if the generated field/resource needs to have a different type than String the only option is to use typed accessors, eg:

buildConfigDouble 'RATE', buildProperties.bar['rate'].or{ 1.0 }.double

It would be better if all the buildConfig* and resValue* utilities exposed by the plugin worked directly with Entry instances, eg:

buildConfigDouble 'RATE' buildProperties.bar['rate'].or { 1.0 }

This will incidentally make obsolete buildConfigProperty and resValueProperty, which implicitly convert any value to String.

Clarify "using" syntax

The docs specify how you can reference properties files:

image

but it says file is deprecated:

image

where clicking through seems to link to the wrong method?

image

buildProperties {
    using letterboxd.properties
}

says could not find method using()

How can I get rid of the deprecation warning?

Cannot load version property from file

At the moment you can't load a property named version from your properties file.

Example file, myprops.properties:

name=pirata
version=1.2.3

If you attempt to load the version property you'll always get unspecified. This happens because PojoMetaMethodSite defines a version field that collides with the Entry's one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.