Giter VIP home page Giter VIP logo

gradle-config-plugin's Introduction

Gradle Config Plugin

(aka Gradle Property Utilities Plugin)

Gradle plugin to expand dotted properties into nested objects.

In Java applications it is a common practice to use property names in dotted notation, e.g. aws.s3.bucket. It also may be desirable to work with the values as nested structures.

Alas, dotted names are not auto-expanded by Groovy. Thus, properties set on the command line or in gradle.properties file can be accessed in a build script only via plain string keys, e.g. project.ext['aws.s3.bucket'].

This tiny plugin for Gradle aspires to do the trick.

JDK 1.7 is required.

The latest stable version is 0.4.5.

Quick Start

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath group: 'com.esyfur', name: 'gradle-config-plugin', version: '0.4.+'
    }
}

apply plugin: 'config'

Usage

gradle test -Pbuild.name=myTestBuild -Pbuild.version=1.23

build.name and build.version values will now be available in build.gradle as nested objects:

task test << {
    println 'Build Name:    ' + config.build.name
    println 'Build Version: ' + config.build.version
}

It is also possible to leverage the safe navigation operator:

assert config.aws.s3?.bucket ?: 'com.esyfur.gradle' == 'com.esyfur.gradle'

Configuration

To avoid name collisions, the plugin creates config property and uses it as the root scope for all processed values.

It is possible to change the name of the property by defining config.namespace value in gradle.properties:

config.namespace = cfg

Loading .properties files

Gradle automatically reads settings from gradle.properties files in project build and user home directories. But no concise ways provided to load arbitrary Properties files.

This plugin adds a handy load() helper for that:

cfgutil.load('commons')

The method accepts java.nio.file.Path, java.io.File or a String. If the given path isn't absolute, it is treated as relative to projectDir. If the file name does not have an extension, .properties is assumed.

Acknowledgment

The implementation is trivial and was initially borrowed from @OverZealous's answer on StackOverflow, but in v0.3 it was replaced with ConfigObject and ConfigSlurper.

gradle-config-plugin's People

Contributors

esycat avatar

Watchers

 avatar  avatar

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.