Giter Site home page Giter Site logo

gladed / gradle-android-git-version Goto Github PK

View Code? Open in Web Editor NEW
268.0 5.0 30.0 185 KB

A gradle plugin to calculate Android-friendly version names and codes from git tags

License: Apache License 2.0

Groovy 100.00%
android gradle-plugin git versioning

gradle-android-git-version's Introduction

gradle-android-git-version

CircleCI

A gradle plugin to calculate Android-friendly version names and codes from git tags.

If you are tired of manually updating your Android build files for each release, or generating builds that you can't trace back to code, then this plugin is for you!

Installation and Use

1. Add the plugin to your project

Add plugins block to the top of your app/build.gradle (or equivalent):

plugins {
    id 'com.gladed.androidgitversion' version '0.4.14'
}

2. Set versionName and versionCode from plugin results

android {
    // ...
    defaultConfig {
        // ...
        versionName androidGitVersion.name()
        versionCode androidGitVersion.code()

3. Use a git tag to specify your version number (see Semantic Versioning)

$ git tag 1.2.3
$ gradle --quiet androidGitVersion
androidGitVersion.name	1.2.3
androidGitVersion.code	1002003

For more advanced usage, read on...

Tag format

Tags should look like 1 or 3.14 or 1.12.5. There must be at least one tag of this format reachable from the current commit, or the generated version name will be "unknown".

Any suffix after the version number in the tag (such as -release4 in 1.2.3-release4) is included in the version name, but is ignored when generating the version code.

In some cases, you'll have more than one version being generated in a single repo. In this case you can supply a prefix like "lib-" to separate sets of tags. See prefix below for more.

Intermediate Versions

Builds from non-tagged commits will generate a name() something like this:

1.2.3-2-93411ff-fix_issue5-dirty

In the example above, the components are:

1.2.3 -2 -93411ff -fix_issue5 -dirty
Most recent tag Number of commits since tag Commit SHA prefix Branch name Dirty indicator

Branches listed in hideBranches won't appear.

"-dirty" will only appear if the current branch has uncommitted changes.

You can customize this layout with format (see below).

Version Codes

Version codes are calculated relative to the most recent tag. For example, version 1.2.3 will have a version code of 1002003.

You can customize the scheme used to generate version codes with codeFormat (see below).

Methods

name() returns the current version name.

code() returns the current version code.

flush() flushes the internal cache of information about the git repo, in the event you have a gradle task that makes changes to the repo.

Tasks

androidGitVersion prints the name and code, as shown above.

androidGitVersionName prints only the name.

androidGitVersionCode prints only the code.

Usage Notes

  • To save on bandwidth, CI servers may default to a "shallow" clone of your repo having no revision history, or may omit the pulling of tags. This hides the commit history and will prevent this plugin from accurately identifying the name or version code. This will result in an error not seen on your local build machine:

    Building app with versionName [untagged_814fca9-812f...9b8], versionCode [0]
    

    To address this, configure your CI project to pull enough history (e.g. git fetch --depth=100 --tags) to reach recent commits and tags of interest.

  • git worktree is not supported.

Configuration Properties

You can configure how names and codes are generated by adding an androidGitVersion block to your project's build.gradle file, before the android block. For example:

androidGitVersion {
    abis = ["armeabi":1, "armeabi-v7a":2 ]
    baseCode 200000
    codeFormat 'MNNPPP'
    commitHashLength = 8
    format '%tag%%.count%%<commit>%%-branch%%...dirty%'
    hideBranches = [ 'develop' ]
    onlyIn 'my-library'
    prefix 'lib-'
    tagPattern(/^R[0-9]+.*/)
    untrackedIsDirty = false
}

android {
    // ...
}

abis (map of String:int)

abis indicate how ABI platforms are mapped to integer codes. These integer codes are inserted into the A place in codeFormat.

The default abis are:

['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9 ]

baseCode (int)

baseCode sets a floor for all generated version codes (that is, it is added to all generated version codes). Use this when you have already released a version with a code, and don't want to go backwards.

The default is baseCode 0, enforcing no minimum version code value.

codeFormat (string)

codeFormat defines a scheme for building the version code. Each character corresponds to a reserved decimal place in the resulting code:

  • M for the Major version number (1.x.x)
  • N for the Minor version number (x.1.x)
  • P for the Patch version number (x.x.1)
  • R for the Revision number (e.g. x.x.x-rc1)
  • B for the build number (revisions since last tag)
  • A for the ABI platform code [1]
  • X for a blank place filled with 0

[1] if you use A you must call variants to tell the plugin about your project's build variants. For example:

android {
    ...
    androidGitVersion {
        codeFormat = 'AMNNPPP'
        variants applicationVariants
    }
}

Note that changing the version code scheme for a released Android project can cause problems if your new version code does not increase monotonically. Consider baseCode if you are changing code formats from a prior release.

Android version codes are limited to a maximum version code of 2100000000. As a result, codeFormat only allows you to specify 9 digits.

The default is codeFormat 'MMMNNNPPP', leaving 3 digits for each portion of the semantic version. A shorter code format such as MNNPPP is highly recommended.

commitHashLength (int)

commitHashLength specifies how many characters to use from the beginning of commit SHA hash (e.g. commit in format). Values from 4 to 40 are valid.

The default length is 7 (similar to git describe --tags).

hideBranches (list of strings/regexes)

hideBranches identifies branch names to be hidden from the version name for intermediate (untagged) commits.

For example, if 'master' is your development branch, hideBranches ['master'] results in build names like 1.2-38-9effe2a instead of 1.2-38-master-9effe2a.

Note that each element of hideBranches is interpreted as a regex pattern, for example, [ 'master', 'feature/.*' ].

The default is hideBranches [ 'master', 'release' ], meaning that intermediate builds will not show these branch names.

format (string)

format defines the form of the version name.

Parts may include:

  • tag (the last tag)
  • count (number of commits, if any, since last tag)
  • commit (most recent commit prefix, if any, since the last tag)
  • branch (branch name, if current branch is not in hideBranches)
  • dirty (inserting the word "dirty" if the build was made with uncommitted changes).
  • describe (the string generated by git.describe, similar to the output from git describe --tags. Warning: This command works differently from the rest of this plugin and result in different tag, count, or commit parts than those used to generate the version code.)

Parts are delimited as %<PARTNAME>%. Any other characters appearing between % marks are preserved.

Parts are sometimes omitted (such as a branch name listed by hideBranches). In this case the entire part will not appear.

The default is format "%tag%%-count%%-commit%%-branch%%-dirty%"

onlyIn (string)

onlyIn sets a required path for relevant file changes. Commits that change files in this path will count, while other commits will be ignored for versioning purposes.

For example, consider this directory tree:

+-- my-app/
    +-- .git/
    +-- build.gradle
    +-- app/
    |   +-- build.gradle
    |   +-- src/
    +-- lib/
        +-- build.gradle
        +-- src/

If my-app/lib/build.gradle is configured with onlyIn 'lib', then changes to files in other paths (like my-app/build.gradle or my-app/app/src) will not affect the version name.

The default is onlyIn '', including all paths.

prefix (string)

prefix sets the required prefix for any relevant version tag. For example, with prefix 'lib-', the tag lib-1.5 is used to determine the version, while tags like 1.0 and app-2.4.2 are ignored. When found, the prefix is removed from the front of the final version name.

The default is prefix '', matching all numeric version tags.

tagPattern (string/regex)

tagPattern limits the search for the most recent version tag to those that match the pattern. For example, tagPattern(/^v[0-9]+.*) limits matches to tags like v1.6.

If both prefix and tagPattern are used, the prefix strings should be included in the tagPattern.

The default is tagPattern(/^$prefix[0-9]+.*/), finding all tags beginning with the prefix (if specified) and a digit.

untrackedIsDirty (boolean)

When untrackedIsDirty is true, a version is considered dirty when any untracked files are detected in the repo's directory.

The default is untrackedIsDirty false; only tracked files are considered when deciding on "dirty".

Deprecated Configuration Properties

See DEPRECATED.md.

Version History

See HISTORY.md.

License

All code here is Copyright 2015-2019 by Glade Diviney, and licensed under the Apache 2.0 License.

gradle-android-git-version's People

Contributors

alexendoo avatar cellscape avatar gladediviney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gradle-android-git-version's Issues

Plugin causes pre-commit hook to fail

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().

2 tags that match pattern on last commit produces NumberFormatException: For input string: ""

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)
...

androidGitVersion.code() without tag

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

Take shorter of two tags?

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.

[request] customize version name output format

I'm lazy (as many devs ๐Ÿ˜‰ ) and I want to versioning my app in such format 1.2.34

  • 1 - just digit as many others
  • 2 - number of sprint
  • 34 - number of commits since last tag

As you can see I want to:

  • change number of commits since tag from dash to dot: -%d to .%d
  • avoid display commit checksum
  • in some cases even avoid dirty flag

All of above could be defined in androidGitVersion settings, eg:

androidGitVersion {
    commitsSinceTagPrefix .
    commitChecksumVisible false
    dirtyVisible false
}

Look for best # in tag history?

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:

  • The user can create TWO branches for release. One for tags, and one for commits, and mergeback only from the branch used for commits. So there will be no unexpected tags in ancestry.
  • The plugin could (optionally?) follow parent # 1 in a merge, ignoring other ancestors. But is this a valid assumption?
  • The plugin could (optionally?) look for the oldest tag in the ancestry instead of the most recent (e.g. if [1] is 1.0 while [2] is 1.1).
  • ???

Feature: Option to add commit count to baseCode

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.

Provide direct access to git scan Results

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
    }

Dirty version although there are no uncommited changes

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:
grafik

That's what i get after building or executing "gradle --quiet androidGitVersion":
grafik

do you any idea why that is happening? Is there something else i can have a look at or provide some other logs?

Missing tags should break the build

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.

Add RegEx for Hiding Branch Names

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.-]", "_")
}

[request] versionCode multipler depended on version part

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

Java version not locked down

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.

versionname started to include very long sha hash

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
grafik

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....

Question: Using git version for subprojects

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.

Need to sync gradle after every commit

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?

Does the library fall back if git is not present?

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?

Recommended tagPattern format produce syntax error.

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]+.*/

}`

Incorrect versionCode and tag name

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.

"format" argument not being used

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

SplitAPK Support?

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

Deprecation warning

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.

Could not find com.android.tools:common:25.3.3.

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

Merges can trick us into finding wrong tag

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.

Jacoco Compatability

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!

Unmatched tagPattern + prefix produces an error

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)

Version code extensions

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.

Release candidate in versionName, versionCode

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?

How to use for a project with multiple submodules?

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.

gradle build failed

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.

untracked files not committed not considered 'dirty'. Intentional?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.