gradle-expand-props

Gradle plugin to expand dotted properties into nested maps.

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

com.esyfur
ArtifactId

ArtifactId

gradle-expand-props
Last Version

Last Version

0.3.4
Release Date

Release Date

Type

Type

jar
Description

Description

gradle-expand-props
Gradle plugin to expand dotted properties into nested maps.
Project URL

Project URL

https://github.com/esycat/gradle-props-util
Project Organization

Project Organization

Persic Entertainment
Source Code Management

Source Code Management

https://github.com/esycat/gradle-props-util

Download gradle-expand-props

How to add to project

<!-- https://jarcasting.com/artifacts/com.esyfur/gradle-expand-props/ -->
<dependency>
    <groupId>com.esyfur</groupId>
    <artifactId>gradle-expand-props</artifactId>
    <version>0.3.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.esyfur/gradle-expand-props/
implementation 'com.esyfur:gradle-expand-props:0.3.4'
// https://jarcasting.com/artifacts/com.esyfur/gradle-expand-props/
implementation ("com.esyfur:gradle-expand-props:0.3.4")
'com.esyfur:gradle-expand-props:jar:0.3.4'
<dependency org="com.esyfur" name="gradle-expand-props" rev="0.3.4">
  <artifact name="gradle-expand-props" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.esyfur', module='gradle-expand-props', version='0.3.4')
)
libraryDependencies += "com.esyfur" % "gradle-expand-props" % "0.3.4"
[com.esyfur/gradle-expand-props "0.3.4"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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.

Versions

Version
0.3.4
0.3.2
0.3.1
0.2.4
0.2.3
0.1.23