Gradle Config Plugin


Source link: https://github.com/tmiyamon/gradle-config

Gradle Config Plugin

This plugin helps you to easily handle variant specific settings with yaml format.

Usage

buildscript {

repositories {

  maven {

 url "https://plugins.gradle.org/m2/"
  
}

}

dependencies {

  classpath "gradle.plugin.com.tmiyamon:gradle-config:0.2.1"

}
 
}
  apply plugin: 'com.android.application' apply plugin: "com.tmiyamon.config"

Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

plugins {

id "com.tmiyamon.config" version "0.2.1" 
}
 

Settings class

The entries in config yaml will be available in Settings class as static members:

Settings.entry 

Nested entries are supported:

Settings.entry.some_entry 

Config files

Config entries are generated from:

config/default.yml config/default_secret.yml config/${
productFlavor
}
.yml config/${
productFlavor
}
_secret.yml config/${
buildType
}
.yml config/${
buildType
}
_secret.yml 

The lower one overwrites upper one deeply. The purpose of loading settings files with suffix _secret is to avoid to commit the secret files to remote repository. If you want to use this feature, don't forget to include those files to your .gitignore:

*_secret.yml 

Accessing Configuration Settings

Consider the following config files.

config/default.yml

size: 1 server: google.com

config/debug.yml

size: 2 server: google.com section:
size: 3
servers: [ {
name: yahoo.com
}
, {
name: amazon.com
}
 ]

Notice that the variant specific config entries overwrite the common entries.

Settings.size
// => 2 Settings.server // => google.com

Notice that object member notation is maintained even in nested entries.

Settings.section.size // => 3

Notice array notation and object member notation is maintained.

Settings.section.servers.get(0).name // => yahoo.com Settings.section.servers.get(1).name // => amazon.com

Type

Consider this config file:

string_entry: string int_entry: 1 double_entry: 1.0 date_entry: 2001-11-23 15:03:17 list_entry:
- 1
- 2 failed_list_entry:
- 1
- 'test' object_entry:
entry_a: 1
entry_b: 2 list_of_map_entry:
- a: 'a1'
  b: 'b1'
- a: 'a2'
  b: 'b2'

The snakeyaml library this plugin uses provides the following basic type conversions:

Integer i = Settings.int_entry; String s = Settings.string_entry; Double d = Settings.double_entry; Date da = Settings.date_entry; List<Integer> list = Settings.list_entry;

The list with mixed type elements are not supported and throw an exception.

Error:Execution failed for task ':app:generateDevDebugSettings'. > Not supported list with mixed type: [class java.lang.Integer, class java.lang.String] 

The nested map entries are converted a generated class to achieve dot access.

Settings.ObjectEntry oe = Settings.object_entry; Integer entryA = object_entry.entry_a; Integer entryB = object_entry.entry_b;

Also, the list of map are supported.

List<Settings.ListOfMapEntryElement> entries = Settings.list_of_map_entry;

Known issues

Not found Settings class

Sometimes Android Studio does not detect generated Settings class. When you fact to this problem, Refresh all Gradle projects in the right pane of Android Studio may be helpful.

License

Copyright 2015 Takuya Miyamoto  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

A timetable designed for planning employees to projects.

  • You only need the name of the plan, the person's name, and a start & end date.
  • No need for multi-dimensional arrays
  • No need to calculate the X,Y / row,colum
  • Pannable in X and Y
  • Optimized for best performance
  • Multiple items are merged in a single row.

WeekViewSwipeable is a simple view for showing data in weekly format. It supports swiping between weeks and automatically fitting data to the current date.

An Android Layout Manager to create a gridview with cells of different sizes inspired by Flow Layout for iOS.

EditTextView suggests and fills up email domains.

A library for display a few images in one MultiImageView like avatar of group chat.

This library fits your GridView with its contents to a given size.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes