Skip to content
Permalink
Browse files

Version 2.0.0

- The plugin now evaluates the run tasks in silent mode.
- Resolves #19 - Added optional attribute 'incrementOn'.
- Resolves #21 - First run on Gradle syncing (gradle <no tasks>) will generate the properties file with default values.
- New values are now saved when all tasks have been completed and build is finished.
- Added more default save tasks for attribute 'saveOn'.
- An info log line is produced with the outcome of the execution state showing which task triggered the saving.
- When gradle is executed without tasks the evaluation is skipped and a warning log informs the user.
- Added colors and bold effects to the logs.
- General code and logs improvements.
- Fixes #18 - Android bundle support: the correct task to monitor is 'bundleRelease'.
- Removed deprecated features.

Full release notes: https://github.com/davideas/GrabVer/releases/tag/2.0.0
  • Loading branch information...
davideas committed Jun 17, 2019
1 parent a261b2a commit a988c49edaabca3db14f70ecea63f4a790ce3d20
115 README.md
@@ -1,7 +1,9 @@
[![Licence](https://img.shields.io/badge/Licence-Apache2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Gradle](https://img.shields.io/badge/Gradle-Plugin-green.svg)](https://plugins.gradle.org/plugin/eu.davidea.grabver)
[![Gradle](https://img.shields.io/badge/Android-√-darkgreen.svg)](https://developer.android.com)
[![Gradle](https://img.shields.io/badge/Spring_Boot-√-darkgreen.svg)](https://spring.io/projects/spring-boot)
[![Licence](https://img.shields.io/badge/Licence-Apache2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)

<img src="./art/grabver.png">
![Logo](./art/grabver.png)

An easy Gradle plugin that follows [semver.org](http://semver.org/) rules to
automatically generate the _Patch_ version, _Build_ number and _Code_ version, while _Major_,
@@ -14,99 +16,124 @@ only 2 variables.
Inspired from <a href='https://andreborud.com/android-studio-automatic-incremental-gradle-versioning/'>Android Studio
Automatic Incremental Gradle Versioning</a>. Customized into library with PreRelease, Auto-Reset and Sub-Modules features.</p>

> Easy to apply, it _works with any project type with sub modules too._
> Easy to apply, it _works with **any** project type with sub modules too._
## Rules
_major_: User defined value for breaking changes.<br>
_minor_: User defined value for new features, but backwards compatible.<br>
_patch_: User defined value (or auto-generated value) for backwards compatible bug fixes only.<br>
_preRelease_: Optional, user defined value for pre-releases suffix.<br>
_saveOn_: Optional, saving versioning file depending by the task-name specified here (default: _compileJava, bundle, assembleDebug & assembleRelease_).<br>
_~~dependsOn~~_ (use _saveOn_).<br>

**build** - Increases at each build.<br>
**code** - Increases at each release.<br>
###### User values
**major**: Required, user defined value for breaking changes.<br>
**minor**: Required, user defined value for new features, but backwards compatible. If you increase _Major_ version, this value must be coherent(=0).<br>
**patch**: Optional, user defined value (or auto-generated value) for backwards compatible bug fixes only.<br>
**preRelease**: Optional, user defined value for pre-releases suffix.<br>
**incrementOn**: Optional, custom task name to trigger the increase of the version (default: `assembleRelease`, `bundleRelease`, `grabverRelease`).<br>
**saveOn**: Optional, custom task name for which you want to save the versioning file (default: `build`, `assembleDebug`, `assembleRelease`, `bundleDebug`, `bundleRelease`, `grabverRelease`, `jar`, `war`, `explodedWar`).

###### Calculation
**patch** - If not specified by user, increases at each release, but it auto resets back to 0 when _Minor_ or _Major_ version changes or if _preRelease_ is set.<br>
**minor** - User defined value, it must be coherent(=0) if you increase _Major_ version.

Auto-skip versioning when 'clean', 'test' or 'grabverSkip' tasks are enqueued in command line.
**build** - Increases at each build.<br>
**code** - Increases at each release.

## Installation
Configure script dependencies in the project _build.gradle_ file:
``` groovy
``` gradle
buildscript {
repositories {
// Using Bintray repository:
maven { url "http://dl.bintray.com/davideas/maven" }
// or Gradle Plugins repository:
// or Gradle plugins repository:
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
// Using Bintray repository:
classpath 'eu.davidea:grabver:1.0.1'
// or with Gradle Plugins Repository
classpath "gradle.plugin.eu.davidea:grabver:1.0.1"
classpath 'eu.davidea:grabver:2.0.0'
// or with Gradle plugins repository
classpath "gradle.plugin.eu.davidea:grabver:2.0.0"
}
}
```

## Usage
### 1. Version configuration
Apply the plugin in the _module_ you desire, it will create a properties file under that module!
``` groovy
apply plugin: 'eu.davidea.grabver'
``` gradle
plugins {
...
id: 'eu.davidea.grabver'
}
versioning {
// required (number)
// Required (number)
major 1
minor 0
// optional, force custom patch (number)
// Optional, force custom patch (number)
patch 7
// optional (any string)
// Optional (any string)
preRelease "RC1"
// optional, save new versioning on file on specified <task-name>
// Optional, custom task name to trigger the increase of the version
increaseOn [or incrementOn] "<task-name>"
// Optional, custom task name for which you want to save the versioning file
saveOn "<task-name>"
}
```

### 2. Grab your new version
``` groovy
``` gradle
versioning.major
versioning.minor
versioning.patch
versioning.build
versioning.preRelease
versioning.code // needed for all Android projects
versioning.name // output: "major.minor.patch[-preRelease]"
versioning.fullVersionName // output: "major.minor.patch[-preRelease] #build built on yyyy.mm.dd"
versioning.builtOn // output: " built on yyyy.mm.dd"
versioning.date // or .getDate([format]) - default "yyyy.mm.dd"
versioning.code // needed for all Android projects
versioning.name // output: "major.minor.patch[-preRelease]"
versioning.fullName // output: "major.minor.patch[-preRelease] #build built on yyyy.mm.dd"
versioning.builtOn // output: " built on yyyy.mm.dd"
versioning.date // or versioning.getDate([format]) - default "yyyy.mm.dd"
```
> **Note:** To trigger the evaluation, the user must grab one of the above attribute.
### 3. Run it
- Via command line:
```
// To increase build number only:
// - Code and Patch remain unchanged
gradle [build | assembleDebug]
// To increase build, patch and code:
// Code and Patch are increased because of releases:
// - Code is increased if exists a task that contains: "bundle", "grabverRelease", ":module:assembleRelease"
// - But Patch can be resetted if Major or Minor is changed or if preRelease is set
gradle [grabverRelease | assembleRelease]
/**
* To increment build number only:
* - Code and Patch remain unchanged
*/
gradle [build | jar | war | explodedWar | assembleDebug | bundleDebug]
/**
* To increment build, patch and code:
* Code and Patch are incremented because of releases:
* - Code is incremented if exists a release task.
* Example: "bundleRelease", "grabverRelease", ":module:assembleRelease"
* - But Patch may be resetted if Major or Minor is changed or if preRelease is set
*/
gradle [assembleRelease | bundleRelease | grabverRelease]
```
- In Android Studio:
- via menu _build > Build APK_ (assembleDebug) | _Generate signed APK_ (assembleRelease).
- via menu _build > Build Bundle / APK_ (bundleDebug | assembleDebug)
- via menu _build > Generate Signed Bundle / APK_ (bundleRelease | assembleRelease).
- by _running the App_ (assembleDebug | assembleRelease, depending by the build variant).

**Note:** File `version.properties` is auto-generated, but once it's created, you can modify its content
From [version 2](https://github.com/davideas/GrabVer/releases/tag/2.0.0), the plugin evaluates the run tasks
in silent mode to automatically skip the new version evaluation and to not print unnecessary logs _if_ no save task
was detected. A single warning line is however produced.<br>
Single tasks performed such as _clean, test, flyway_ and **all** third parties invented plugin
tasks out there will not trigger the versioning evaluation. Example:

|Command|Outcome|
|---|---|
|`gradle clean test`|Evaluation skipped|
|`gradle javadoc`|Evaluation skipped|
|`gradle flywayClean`|Evaluation skipped|
|`gradle clean build`|Evaluation triggered and new values saved|
|`gradle clean war grabverRelease`|Evaluation triggered, versioning increased and new values saved|

> **Note:** File `version.properties` is auto-generated, but once it's created, you can modify its content
as of your convenience. Just remember to add it to your Version Control System (from time to time).
# Contributions
Everybody is welcome to improve existing solution.

**Note:** Unit tests work fine if you open the project with IntelliJ Idea, while with Android Studio
> **Note:** Unit tests work fine if you open the project with IntelliJ Idea, while with Android Studio
they don't. Alternatively, you can simulate a real build script by running `gradle install`
and `gradle -b build-test.gradle [grabverRelease]` OR testing with modules `gradle build [grabverRelease]`.
@@ -18,14 +18,31 @@ buildscript {
}
//noinspection GroovyAssignabilityCheck
dependencies {
classpath 'eu.davidea:grabver:1.0.1'
classpath 'eu.davidea:grabver:2.0.0'
}
}

versioning {
major 1
minor 2
preRelease "RC2"
incrementOn "jar"
saveOn "jar"
}
println("TEST - VersionCode: ${versioning.code}")
println("TEST - VersionName: ${versioning.name}")
println("TEST - FullName: ${versioning.fullName}")

repositories {
jcenter()
mavenLocal()
}

dependencies {
implementation gradleApi()
implementation localGroovy()
implementation 'nu.studer:java-ordered-properties:1.0.1'

testImplementation gradleTestKit()
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
println("TEST - VersionCode: " + versioning.code)
println("TEST - VersionName: " + versioning.name)
println("TEST - FullVersionName: " + versioning.fullVersionName)
@@ -6,29 +6,29 @@ buildscript {
}
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.gradle.publish:plugin-publish-plugin:0.9.7'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.gradle.publish:plugin-publish-plugin:0.10.1'
}
}

apply plugin: 'com.gradle.plugin-publish'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'com.gradle.plugin-publish'

repositories {
jcenter()
mavenLocal()
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile gradleApi()
compile localGroovy()
compile 'nu.studer:java-ordered-properties:1.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation gradleApi()
implementation localGroovy()
implementation 'nu.studer:java-ordered-properties:1.0.1'

testCompile gradleTestKit()
testCompile group: 'junit', name: 'junit', version: '4.12'
testImplementation gradleTestKit()
testImplementation group: 'junit', name: 'junit', version: '4.12'
}

ext {
@@ -39,7 +39,7 @@ ext {

// Library Repository
libraryName = 'GrabVer'
libraryVersion = '1.0.1'
libraryVersion = '2.0.0'
displayName = 'Gradle Automatic Build Versioning Plugin'
libraryDescription = 'An easy Gradle plugin that follows semver.org rules to automatically generate the Patch version, Build number and Code version, while Major, Minor and Pre-Release suffix remain under our control.'
libraryLabels = ['semver', 'version', 'versioning', 'build-versioning', 'automatic-versioning', 'intellij-idea', 'android-studio', 'auto-reset']
@@ -74,9 +74,9 @@ pluginBundle {
}

mavenCoordinates {
groupId = project.publishedGroupId
artifactId = project.bintrayName
version = project.libraryVersion
groupId = publishedGroupId
artifactId = bintrayName
version = libraryVersion
}
}

@@ -6,14 +6,15 @@ buildscript {
mavenLocal()
}
dependencies {
classpath 'eu.davidea:grabver:1.0.1'
classpath 'eu.davidea:grabver:2.0.0'
}
}

versioning {
major 1
minor 1
minor 2
incrementOn 'build'
}
println("MODULE_A - VersionCode: " + versioning.code)
println("MODULE_A - VersionName: " + versioning.name)
println("MODULE_A - FullVersionName: " + versioning.fullVersionName)
println("MODULE_A - VersionCode: ${versioning.code}")
println("MODULE_A - VersionName: ${versioning.name}")
println("MODULE_A - FullName: ${versioning.fullName}")
@@ -6,15 +6,14 @@ buildscript {
mavenLocal()
}
dependencies {
classpath 'eu.davidea:grabver:1.0.1'
classpath 'eu.davidea:grabver:2.0.0'
}
}

versioning {
major 2
minor 2
}
println("MODULE_B - VersionCode: " + versioning.code)
println("MODULE_B - VersionName: " + versioning.name)
println("MODULE_B - FullVersionName: " + versioning.fullVersionName)

println("MODULE_B - VersionCode: ${versioning.code}")
println("MODULE_B - VersionName: ${versioning.name}")
println("MODULE_B - FullName: ${versioning.fullName}")
@@ -0,0 +1,77 @@
package eu.davidea.gradle;

public enum ConsoleColors {
// Reset
RESET("\033[0m"), // Text Reset

// Regular Colors
BLACK("\033[0;30m"), // BLACK
RED("\033[0;31m"), // RED
GREEN("\033[0;32m"), // GREEN
YELLOW("\033[0;33m"), // YELLOW
BLUE("\033[0;34m"), // BLUE
PURPLE("\033[0;35m"), // PURPLE
CYAN("\033[0;36m"), // CYAN
WHITE("\033[0;37m"), // WHITE

// Bold
ONLY_BOLD("\033[1m"), // ONLY BOLD
BLACK_BOLD("\033[1;30m"), // BLACK
RED_BOLD("\033[1;31m"), // RED
GREEN_BOLD("\033[1;32m"), // GREEN
YELLOW_BOLD("\033[1;33m"), // YELLOW
BLUE_BOLD("\033[1;34m"), // BLUE
PURPLE_BOLD("\033[1;35m"), // PURPLE
CYAN_BOLD("\033[1;36m"), // CYAN
WHITE_BOLD("\033[1;37m"), // WHITE

// Underline
ONLY_UNDERLINED("\033[4m"), // ONLY UNDERLINED
BLACK_UNDERLINED("\033[4;30m"), // BLACK
RED_UNDERLINED("\033[4;31m"), // RED
GREEN_UNDERLINED("\033[4;32m"), // GREEN
YELLOW_UNDERLINED("\033[4;33m"), // YELLOW
BLUE_UNDERLINED("\033[4;34m"), // BLUE
PURPLE_UNDERLINED("\033[4;35m"), // PURPLE
CYAN_UNDERLINED("\033[4;36m"), // CYAN
WHITE_UNDERLINED("\033[4;37m"), // WHITE

// High Intensity
BLACK_BRIGHT("\033[0;90m"), // BLACK
RED_BRIGHT("\033[0;91m"), // RED
GREEN_BRIGHT("\033[0;92m"), // GREEN
YELLOW_BRIGHT("\033[0;93m"), // YELLOW
BLUE_BRIGHT("\033[0;94m"), // BLUE
PURPLE_BRIGHT("\033[0;95m"), // PURPLE
CYAN_BRIGHT("\033[0;96m"), // CYAN
WHITE_BRIGHT("\033[0;97m"), // WHITE

// Bold High Intensity
BLACK_BOLD_BRIGHT("\033[1;90m"), // BLACK
RED_BOLD_BRIGHT("\033[1;91m"), // RED
GREEN_BOLD_BRIGHT("\033[1;92m"), // GREEN
YELLOW_BOLD_BRIGHT("\033[1;93m"),// YELLOW
BLUE_BOLD_BRIGHT("\033[1;94m"), // BLUE
PURPLE_BOLD_BRIGHT("\033[1;95m"),// PURPLE
CYAN_BOLD_BRIGHT("\033[1;96m"), // CYAN
WHITE_BOLD_BRIGHT("\033[1;97m"); // WHITE

String code;

ConsoleColors(String code) {
this.code = code;
}

public static String bold(String message) {
return ConsoleColors.ONLY_BOLD.code + message + ConsoleColors.RESET.code;
}

public static String underline(String message) {
return ConsoleColors.ONLY_UNDERLINED.code + message + ConsoleColors.RESET.code;
}

public static String styler(ConsoleColors color, String message) {
return color.code + message + ConsoleColors.RESET.code;
}

}

0 comments on commit a988c49

Please sign in to comment.
You can’t perform that action at this time.