gladed / gradle-android-git-version Goto Github PK
View Code? Open in Web Editor NEWA gradle plugin to calculate Android-friendly version names and codes from git tags
License: Apache License 2.0
A gradle plugin to calculate Android-friendly version names and codes from git tags
License: Apache License 2.0
hideBranches option?
A project with 1.0 gets Android Code of 10000. But 1.0.0 gets 100000000.
There should be a setting for how many sub-digits we are going to use when calculating the version code.
Hello!
Your plugin is cool, but I have an issue.
Every time I commit changes Android Studio starts failing apk installation.
It prints a message like this:
The APK file path/to/app-PREVIOUS_COMMIT_VERSION_INFO.apk does not exist on disk.
Or it just installs the previously built apk.
I have to perform Gradle sync to fix this. And it's very annoying.
Tried to add something like this to my build.gradle, but it didn't help:
task flushGitInfo {
android.applicationVariants.all { variant ->
variant.assemble.doFirst {
androidGitVersion.flush()
}
}
}
So is it possible to do something to avoid Gradle synchronization?
When compiling with a different JDK version you could get "Unsupported major.minor version 52.0". So the plugin should lock down the targetCompatibility and sourceCompatibility settings for a better experience.
I can set for androidGitVersion.name() next format:
format = '%branch%'
So, if I have branch 1.3.2, then I get versionName "1.3.2". OK.
androidGitVersion.code() return always 0, because I do set tag value.
But I think it's normal use case:
git branch = 1.3.2
androidGitVersion.name() = "1.3.2'
androidGitVersion.code() = 103020
Instead you get the rather noisy output including both name/code when you probably just want name.
Just for completeness, this issue was fixed in #24 and released in 0.2.20.
It would be great if it was possible to set codeFormat to year, month, day, hour or minute. I would prefer an autoincremental versionCode instead of a one based on git commits.
Missing an expected tag currently results in untagged
output. But it's not clear why this happens sometimes, and it could easily be missed on a CI server.
So consider having an untagged
result break the build by default with a way to allow it intentionally: allowUntagged = true
.
Great plugin, and I was hoping to convince my team to switch over to using it. I was working on a quick demo to show how easy it was and ran into an edge case where I don't think it works correctly.
Here is the scenario -- I've added a file I intend to check in but haven't yet.
$ git status
On branch develop2
Untracked files:
(use "git add <file>..." to include in what will be committed)
pretend_bug_fix.java
nothing added to commit but untracked files present (use "git add" to track)
Since my I have locally uncommitted changes, I would think that my version name would include the 'dirty' suffix, but it does not:
$ ./gradlew androidGitVersion
:androidGitVersion
androidGitVersion.name 2.1.1
androidGitVersion.code 20101
It's only if I actually mark the the file for add that dirty works.
$ git add pretend_bug_fix.java
$ ./gradlew androidGitVersion
:androidGitVersion
androidGitVersion.name 2.1.1-dirty
androidGitVersion.code 20101
Is this intentional? Is there a way to make this support optional in the plugin configuration?
Thanks.
something is strange and i cannot explain it, because we didn't changed the way how we use your plugin. I think i updated your plugin to latest 4.4 recently, so it could be because of that.
see the following screenshot
here u see that normally we used to have a nice short sha hash, but recently we start to get the full sha hash too after the short one.
this is the gradle code
androidGitVersion {
codeFormat = 'AMMNNPPBB'
variants applicationVariants
hideBranches = ['master']
}
.......and later
versionName androidGitVersion.name()
versionCode androidGitVersion.code()
the build was compiled from master.
if i look at the default for format "%tag%%-count%%-commit%%-branch%%-dirty%"
i don't see why this is happening, as there is only commit, branch(is not there because hidden, sry you don't see this in the screenshot) and dirty(exists at the very end in this example)
for me it seems he is displaying the full sha hash as for the branch name....
I think that they're unnecessary to add multiplier to first digit in tag eg. 1.2.3
could have a version code 120003000
in place of 100020003000
.
We could go even further. In my case I know, that I never reached 1000 version on 2nd part so when I define something like this:
multipler1 1
multipler2 100
multipler3 1000
then for tag 1.2.3
I receive code 12003000
When a certain commit is tagged multiple times, which one should we take?
For example consider a commit like this:
c8ce522 - Final release! (1.0) (1.0.1-rc) (1.0.1b) (1.0.1) (1.0.1-beta4)
What will the version name be? 1.0
is out, but all of the 1.0.1
flavors are currently equivalent, and our behavior is not defined. The only way you can force one it is by creating a new commit.
Going forward I would like to take the shortest version tag of the latest numeric value. Happily, 1.0.1-beta
wins over 1.0.1-alpha
. 1.0.1-rc
wins over 1.0.1-beta
. And 1.0.1
wins over them all.
Means we do twice as much work each time. Bogus.
Hello, I want to add revCount into baseCode. What about adding smth like that:
final Results getResults() {
if(!this.results) {
this.results = scan()
}
return results
}
When using this plugin (which is great btw!) gradle 3.3 emits the following warning:
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0.
Please use Task.doLast(Action) instead.
Still plenty of time before Gradle 5.0, but would be good to fix.
Builds made from non-HEAD should be denoted in the version name produced.
These should only need 1000 per version number not 10000 by default. And this should be configurable, perhaps on a per-digit basis, such as 9.99.9999
If a version code is already in play, would need to add a base number so that we increase continually from a defined point.
In some cases it would be nice to be able to hide all branch names for hide branch names for s set of changes. Adding RegEx support to the hideBranch
field would make this flexible and possible.
Examples:
// Hide ALL branch names
androidGitVersion {
hideBranches = [ '*' ]
}
// Hide branch names in 'master', 'release', 'develop' and all 'feature/*' branches
androidGitVersion {
hideBranches = [ 'master', 'release', 'develop', 'feature/*' ]
}
It looks like this bit of code would need tweaking:
if (!hideBranches.contains(results.branchName)) {
name += "-" + results.branchName.replaceAll("[^a-zA-Z0-9.-]", "_")
}
Just a couple of questions, not really an issue with this library, but I'm wondering if you can help me out.
1.) What happens if the user doesn't have git installed/available on their PATH? Does it just fall back to the base version code? I'm asking because this is one of the issues with my own implementation of git versioning (a very simplistic version), and one of the reasons I'm looking at your library.
Edit: I realise now that JGit is being used, so command line Git is not required.
2.) My naive implementation looks like this:
def gitCommitCount() {
def commitCount = 0
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--all', '--count'
standardOutput stdout
}
commitCount = stdout.toString().trim().toInteger()
}
catch (error) {
println "Error: ${error}"
}
return commitCount
}
When I try to generate a build with my continuous deployment tool (travis), often the versionCode comes out to be lower than the previous build's versionCode. I think this has something to do with tagging/branching affecting the count, but I don't understand git well enough to figure out why.
You seem familiar with git, and I imagine you've probably come across similar issues. Just wondering if you could help me understand where I'm going wrong?
In my flow i have rc in versionName and versionCode for testers. Can i with your plugin read some data from git tag and interpreted it like rc number? Or i can write some code for support that feature. What you think about it?
May be more of a gradle question.
I've seen from #21, that this is supported, but what's the best way of importing the plugin for each submodule?
The current way:
plugins {
id 'com.gladed.androidgitversion' version '0.4.3'
}
Seems to only work if it's done directly in the app build.gradle
, meaning that it needs to be copied each time, and I presume it will need to check for the tags individually each time. Instead, it may be better for me to simply import it once, and get the tags to use for each submodule. I'm not entirely sure how to do that though, so any help would be great.
Currently it seems splitapk is not supported, as we get the same versioncode for every platform. But this should be different like e.g. 9031002 for x64 3031002 for arm64
Cannot read tag names for lightweight tags, causes a crash.
When i add tagPattern from readme tagPattern /^v[0-9]+.*/ i cant sync gradle because of syntax error. I tried quotation marks and many other possible solutions but without success. When i use "" or '' pattern is ignored and tag is untagged. I have gradle version 3.0.1.
Is there any possible solution for that?
Thanks.
`androidGitVersion {
baseCode 1
codeFormat 'MNNPPP'
format "%tag%%-commit%%-dirty%"
tagPattern /^v[0-9]+.*/
}`
Hi there,
I would enjoy using this plugin but when I try, here is the error message I get.
Error:Cause: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
and my app build.gradle looks like this
plugins {
id "com.gladed.androidgitversion" version "0.2.21"
}
apply plugin: 'com.android.application'
...
...
defaultConfig {
applicationId xxxx.xx.xxx
minSdkVersion 19
targetSdkVersion 25
versionName androidGitVersion.name()
versionCode androidGitVersion.code()
...
}
.....
Am I doing something wrong ?
Thanks for your help.
androidGitVersion version 0.4.0
with build.gradle:
prefix ''
tagPattern "${prefix}v[0-9]+.*"
Run command line:
git tag -a v1.0.0-rc.1 -m "v1.0.0 RC1"
git tag -a v1.0.0 -m "v1.0.0"
./gradlew --stacktrace androidGitVersion
Should give a version based on the most recent tag (v1.0.0), but:
FAILURE: Build failed with an exception.
Where:
Build file '/Users/User/Documents/workspace/Project/app/build.gradle' line: 27
What went wrong:
A problem occurred evaluating project ':app'.
For input string: ""
Try:
Run with --info or --debug option to get more log output.
Exception is:
...
Caused by: java.lang.NumberFormatException: For input string: ""
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension$_scan_closure9$_closure13.doCall(AndroidGitVersion.groovy:249)
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension$_scan_closure9.doCall(AndroidGitVersion.groovy:249)
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension.scan(AndroidGitVersion.groovy:245)
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension.code(AndroidGitVersion.groovy:160)
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension$code.call(Unknown Source)
at build_8e0jag8zpised42jud3iwyaxc$_run_closure2$_closure4.doCall(/Users/User/Documents/workspace/Project/app/build.gradle:27)
...
Apparently it should be 25.3.0 now.
A problem occurred configuring project ':app'.
> Could not resolve all files for configuration ':app:classpath'.
> Could not find com.android.tools:common:25.3.3.
Searched in the following locations:
https://plugins.gradle.org/m2/com/android/tools/common/25.3.3/common-25.3.3.pom
https://plugins.gradle.org/m2/com/android/tools/common/25.3.3/common-25.3.3.jar
https://repo.maven.apache.org/maven2/com/android/tools/common/25.3.3/common-25.3.3.pom
https://repo.maven.apache.org/maven2/com/android/tools/common/25.3.3/common-25.3.3.jar
https://dl.google.com/dl/android/maven2/com/android/tools/common/25.3.3/common-25.3.3.pom
https://dl.google.com/dl/android/maven2/com/android/tools/common/25.3.3/common-25.3.3.jar
Required by:
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.build:manifest-merger:25.3.3
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.ddms:ddmlib:25.3.3
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.analytics-library:shared:25.3.3
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools.analytics-library:tracker:25.3.3
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools:sdklib:25.3.3 > com.android.tools.layoutlib:layoutlib-api:25.3.3
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools:sdklib:25.3.3 > com.android.tools:dvlib:25.3.3
project :app > com.gladed.androidgitversion:com.gladed.androidgitversion.gradle.plugin:0.4.5 > gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5 > com.android.tools.build:gradle:2.3.3 > com.android.tools.build:gradle-core:2.3.3 > com.android.tools.build:builder:2.3.3 > com.android.tools:sdklib:25.3.3 > com.android.tools:repository:25.3.3
Do you have any guidance for using this plugin when using the gitflow branching model? Since tags are placed on master
when using gitflow, there is no tag ancestor of the development branch in many cases which means git describe --tags --dirty
is not super helpful when development or feature branches.
Here are some of the relevant GitFlow issues:
We have the problem that since quite some time the versionname is always dirty. First i thought there are uncommited changes in our CI system, but even when building the apk locally i get the "-dirty" versionname. the git repo is clean see here:
That's what i get after building or executing "gradle --quiet androidGitVersion":
do you any idea why that is happening? Is there something else i can have a look at or provide some other logs?
It would be nice if we could have a function that could add on the number of commits to the baseCode as a way of auto incrementing the versions.
Something like:
ext.commitCount = { ->
def repo
def count = 0
try {
repo = new FileRepositoryBuilder()
.readEnvironment()
.findGitDir(project.projectDir)
.build()
} catch (IllegalArgumentException ignore) {
// No repo found
return count
}
def git = Git.wrap(repo)
def commits = git.log().call()
return commits.size()
}
combine this with MMNNPPXX and it will enable constant updates.
When I try to build on a non-tagged version the "format" argument is not respected.
My setup looks like this:
androidGitVersion {
// Code format is determined from the most recent tag, eg 5.0.1
// M: major number (5)
// N: minor number (0)
// P: patch number (1)
// B: build number (# of git revisions since the last tag)
codeFormat = 'MNNPPPBBB'
format = '%tag%--%count%'
}
But the version name looks like this:
5.0.0-RC0-7-d9b05be-d9b05be320ff9b68bb4ff8b72077faafb939d1f3
For projects with multiple APKs it might be nice to slot in other values (API-level, Platform, Screen size, etc.). Right now this is kind of tricky to do.
Consider:
[2] [3]
master: *---*---*---*
\ /
release: *---*
[1]
If there are tags at [1] and [2], what will the commit at [3] be tagged?
Observed: [1] because it's closer in the history.
Expected: [2]
This behavior stems from a difference in how users and git see the world. As a user, I think of a branch as a stream of commits with some merges from other branches. But git only sees a tree of ancestors, with no real privilege shown toward where the branch was before. So all we can really do is look for the nearest tagged commit in the tree of ancestors. Or...?
Workarounds:
1.0
while [2] is 1.1
).See testUnmatchedPrefixedPattern
Hi, I am attempting to use 'gradle-android-git-version ' for versioning on an Android library project using buildToolsVersion 24.0.0 and gradle version 2.2.3. The plugin is doing exactly what we want, but unfortunately merely including it in the plugins block causes our unit test and coverage reports to fail with
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_b0d6a23/Offline;
In the past I've seen error signify version compatibility problems, but I've tried most reasonable jacoco versions without effect.
Are there any known interactions between the git version plugin and Jacoco? Or similar build tools conflicts? Thanks!
When I try to run this task in a pre-commit hook, I get an error:
Bare Repository has neither a working tree, nor an index
with gradle failing on androidGitVersion.code()
.
If the most recent label is called 1.0-beta3 then we should include the whole label in the version name.
The current algorithm is to find the most recent tagged commit in the current commit's history. But that is not always what you want.
Consider:
004 * (master) Merge from release branch
|\
003 | * (release) [1.0] Fix on release branch
| |
002 * | [1.1] Commit on release branch for new version
|/
001 * Pre-release commit
Commit 004
should take tag 1.1 from commit 002
on the master
branch, not tag 1.0
from more recent commit 003
on the release
branch.
I'm getting this output from the terminal (I hope it has all the info you need):
[tamas@tamas-antergos]$ git describe
v0.7
[tamas@tamas-antergos]$ gradle --quiet androidGitVersion
androidGitVersion.name untagged-49-fdfd1cd-fdfd1cd940cffb5fc2fe5d6488b90e38b56585f7-dirty
androidGitVersion.code 0
[tamas@tamas-antergos]$ ./gradlew --version
------------------------------------------------------------
Gradle 2.14.1
------------------------------------------------------------
Build time: 2016-07-18 06:38:37 UTC
Revision: d9e2113d9fb05a5caabba61798bdb8dfdca83719
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_92 (Oracle Corporation 25.92-b14)
OS: Linux 4.8.2-1-ARCH amd64
Tried with light, annotated, and signed tags, with same results.
I'm lazy (as many devs ๐ ) and I want to versioning my app in such format 1.2.34
1
- just digit as many others2
- number of sprint34
- number of commits since last tagAs you can see I want to:
-%d
to .%d
dirty
flagAll of above could be defined in androidGitVersion settings, eg:
androidGitVersion {
commitsSinceTagPrefix .
commitChecksumVisible false
dirtyVisible false
}
A tag like 1.0-release
will cause a NumberFormatException, preventing the core version number from being extracted.
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'org.eclipse.jgit.treewalk.TreeWalk'
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension.containsRelevantChange(AndroidGitVersion.groovy:335)
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension.scan(AndroidGitVersion.groovy:233)
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension.name(AndroidGitVersion.groovy:127)
at com.gladed.gradle.androidgitversion.AndroidGitVersionExtension$name.call(Unknown Source)
at build_bt8r0bnrovd9fp8sw2rpfu3jv$_run_closure1$_closure9.doCall(/home/gladed/project/MopriaPlugin/MopriaPrintLibrary/build.gradle:27)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:70)
What is the best way to add git versioning if I have multiple subprojects?
Say I have a library module and a sample module and they both should have the same version code and name. Currently I'm adding the plugin and settings to both app/build.gradle
and library/build.gradle
but I'm wondering if it could be done in the root gradle through sub projects.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.