Gradle Plugin for Automatic Versioning


Source link: https://github.com/menny/GradleVersion

Version Generator

A very simple Gradle plugin (and/or a factory method) to generate version data based on environment status.

Install

Add the dependency to your buildscript block, in your build.gradle at the top:

buildscript {

  repositories {

...

maven {
 url 'https://jitpack.io' 
}

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

  
}

dependencies {

...

classpath 'com.github.menny:GradleVersion:0.0.4'
  
}
 
}
 

More information about adding dependencies: https://jitpack.io/#menny/GradleVersion/

Usage

In your gradle.build file apply the plugin:

apply plugin: 'net.evendanan.versiongenerator' 

Then, generate the version data

def versionData = versionGenerator.generateVersion(1, 8, 0) 

This will apply the generated version-name to the project.version property. You may want to use the versionData object for other places:

You might want to print out the version info:

println "Building app with ${
versionData.versionName
}
, code ${
versionData.versionCode
}
." 

or, if you are building an Android app, you should also do:

android {

  defaultConfig {

versionCode versionData.versionCode

versionName versionData.versionName
  
}
 
}
 

Generators

The way the version-data is generated is by using a VersionGenerator. Usually, a generator is specific to a local(?) environment, for example the GitBuildVersionGenerator will look at the number of lines in the git history, which will only work in a project that is a git repo. Each generator should also say if it can work in the current local environment. This is the return value of isValidForEnvironment().

Currently, built-in support for:

  • StaticVersionGenerator - always returns the same version number.
  • GitBuildVersionGenerator - uses the number of commits + tags in the local git repo.
  • EnvBuildVersionGenerator.Shippable - uses BUILD_NUMBER environment variable as the version number.
  • EnvBuildVersionGenerator.CircleCi - uses CIRCLE_BUILD_NUM environment variable as the version number.

You can also implement your own generators by extending VersionGenerator. You'll need to implement:

//return `true` is this generator can calculate the version-number at the moment. //this could check for existance of an environment variable, //or some file-system attribute/property (like git support), etc. abstract fun isValidForEnvironment(): Boolean  //return an integer representing the version number. This could be the number of builds //done so far, or the number of commits in the source-control system, etc. protected abstract fun getVersionCode(generationData: GenerationData): Int 

The default generators used are (in order)

1. EnvBuildVersionGenerator.CircleCi 2. EnvBuildVersionGenerator.Shippable 3. GitBuildVersionGenerator 4. StaticVersionGenerator 

You can change that (especially, if you have a new generator) by call generate which an ordered-list of generators to use:

def generators = [

new net.evendanan.versiongenerator.generators.EnvBuildVersionGenerator.CircleCi(1650, 0),

new net.evendanan.versiongenerator.generators.GitBuildVersionGenerator(-2268, 0),

new net.evendanan.versiongenerator.generators.StaticVersionGenerator() ]  def versionData = versionGenerator.generateVersion(1, 8, 0, generators) 

AnySoftKeyboard is using this plugin.

Resources

Unable to execute dex: method ID not in [0, 0xffff]: 65536)

When you get this message, normally it is not because your project itself has too much methods, but you are importing some big .jar libraries.

So the easy solution is to pack your .jar libraries in libs/ folder into a secondary .dex file and load that file before your application starts.

SafeLooper catches unexpected exceptions in Android applications to avoid showing force close dialog.

Cat photos app for Material Design Animation training.

A layout that hide the header when the body is scrolled down and reveal it when the header is scrolled up.

AppIntroAnimation is a set of code snippets to make cool intro screen for your app with special Image Translation and Transformation animation effects. It is very easy to use and customize without adding third party library integrations.

Use Parse REST API for sending Push Notifications.

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