Giter VIP home page Giter VIP logo

gradle-git-version's Introduction

Autorelease

Git-Version Gradle Plugin

Build Status Gradle Plugins Release

When applied, Git-Version adds two methods to the target project.

The first, called gitVersion(), mimics git describe --tags --always --first-parent to determine a version string. It behaves exactly as git describe --tags --always --first-parent method behaves, except that when the repository is in a dirty state, appends .dirty to the version string.

The second, called versionDetails(), returns an object containing the specific details of the version string: the tag name, the commit count since the tag, the current commit hash of HEAD, and an optional branch name of HEAD.

Usage

Apply the plugin using standard Gradle convention:

Groovy

plugins {
    id 'com.palantir.git-version' version '<current version>'
}

Kotlin

plugins {
    id("com.palantir.git-version") version "<current version>"
}

Set the version of a project by calling:

Groovy

version gitVersion()

Kotlin

val gitVersion: groovy.lang.Closure<String> by extra
version = gitVersion()

You can get an object containing more detailed information by calling:

Groovy

def details = versionDetails()
details.lastTag
details.commitDistance
details.gitHash
details.gitHashFull // full 40-character Git commit hash
details.branchName // is null if the repository in detached HEAD mode
details.isCleanTag

Kotlin

val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
val details = versionDetails()
details.lastTag
details.commitDistance
details.gitHash
details.gitHashFull // full 40-character Git commit hash
details.branchName // is null if the repository in detached HEAD mode
details.isCleanTag

You can optionally search a subset of tags with prefix. Example when the tag is [email protected]:

Groovy

gitVersion(prefix:'my-product@') // -> 2.15.0

Kotlin

val gitVersion: groovy.lang.Closure<String> by extra
gitVersion(mapOf("prefix" to "my-product@")) // -> 2.15.0

Valid prefixes are defined by the regex [/@]?([A-Za-z]+[/@-])+.

/Abc/
Abc@
foo-bar@
foo/bar@

Tasks

This plugin adds a printVersion task, which will echo the project's configured version to standard-out.

License

This plugin is made available under the Apache 2.0 License.

gradle-git-version's People

Contributors

ash211 avatar bmarcaur avatar carterkozak avatar crogers avatar dansanduleac avatar delta003 avatar edsonschlei avatar esword avatar ferozco avatar iamdanfox avatar jeremyjliu avatar jmcampanini avatar markelliot avatar matthew-dailey avatar matthewmaclean avatar nmiyake avatar pkoenig10 avatar rahij avatar svc-autorelease avatar svc-excavator-bot avatar sya-ri avatar timyates avatar uschi2000 avatar wtanaka avatar yiweny 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  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

gradle-git-version's Issues

version could be wrong when there are more than 1 tags on the commit

when there's 1.9.0 and 1.10.0 as annotated tags for a commit, 1.9.0 will be returned (probably because it's the first thing in a list thats sorted alphabetically). it should probably be sorted via semver and always return the larger version instead.

notice that this only happens because of the string "9" is greater than "1". it's fine on other versions

isSnapshot-like functionality

would it make sense to have the plugin expose whether or not it's directly on a tag? this could be useful for determining whether or not something is a snapshot (or an in-between-tags build) vs a tagged build.

Cache gitVersion() result

if you do

allprojects {
  version gitVersion()
}

you will compute version for every subproject even though they're in the same repo. This increases the runtime by around ~0.5s per subproject. We should cache the result since it won't change across projects.

Document usage with kotlin dsl

What happened?

I could not find documentation how to use the functions added by this plugin with kotlin dsl.

What did you want to happen?

Find in the README something like the following:

val gitVersion: groovy.lang.Closure<String> by extra
version = gitVersion(mapOf ("prefix" to "v-"))

Strict prefix regex

Hi,

I would ask You, whether it's possible to change prefix regex to less strict one. I'm using following tags in my project: app_name__x.y.z (where x.y.z is version). I don't like to change my tags schema, because my pipeline relays on it, so I'm unable to use this plugin.

Task.leftShift(Closure) deprecation warnings with gradle 3.2

On version 0.4.0, this stack trace appears during the configuration step (when running with --info)

[2016-11-21 09:59:41] The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
[2016-11-21 09:59:41] 	at org.gradle.api.internal.AbstractTask.leftShift(AbstractTask.java:505)
[2016-11-21 09:59:41] 	at org.gradle.api.Task$leftShift.call(Unknown Source)
[2016-11-21 09:59:41] 	at com.palantir.gradle.gitversion.GitVersionPlugin.apply(GitVersionPlugin.groovy:45)
[2016-11-21 09:59:41] 	at com.palantir.gradle.gitversion.GitVersionPlugin.apply(GitVersionPlugin.groovy)
[2016-11-21 09:59:41] 	at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
[2016-11-21 09:59:41] 	at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:43)
[2016-11-21 09:59:41] 	at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:139)
[2016-11-21 09:59:41] 	at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:112)
[2016-11-21 09:59:41] 	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$5.run(DefaultPluginRequestApplicator.java:174)
[2016-11-21 09:59:41] 	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:212)
[2016-11-21 09:59:41] 	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:171)
[2016-11-21 09:59:41] 	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156)
[2016-11-21 09:59:41] 	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
[2016-11-21 09:59:41] 	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
[2016-11-21 09:59:41] 	at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
[2016-11-21 09:59:41] 	at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
[2016-11-21 09:59:41] 	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:573)
[2016-11-21 09:59:41] 	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:125)
[2016-11-21 09:59:41] 	at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42)
[2016-11-21 09:59:41] 	at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
[2016-11-21 09:59:41] 	at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLauncher.java:162)
[2016-11-21 09:59:41] 	at org.gradle.internal.Factories$1.create(Factories.java:25)
[2016-11-21 09:59:41] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
[2016-11-21 09:59:41] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
[2016-11-21 09:59:41] 	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:159)
[2016-11-21 09:59:41] 	at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:36)
[2016-11-21 09:59:41] 	at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:118)
[2016-11-21 09:59:41] 	at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:112)
[2016-11-21 09:59:41] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
[2016-11-21 09:59:41] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
[2016-11-21 09:59:41] 	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:112)
[2016-11-21 09:59:41] 	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:98)
[2016-11-21 09:59:41] 	at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:66)
[2016-11-21 09:59:41] 	at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
[2016-11-21 09:59:41] 	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
[2016-11-21 09:59:41] 	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
[2016-11-21 09:59:41] 	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
[2016-11-21 09:59:41] 	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
[2016-11-21 09:59:41] 	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
[2016-11-21 09:59:41] 	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
[2016-11-21 09:59:41] 	at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
[2016-11-21 09:59:41] 	at org.gradle.util.Swapper.swap(Swapper.java:38)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
[2016-11-21 09:59:41] 	at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:293)
[2016-11-21 09:59:41] 	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
[2016-11-21 09:59:41] 	at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
[2016-11-21 09:59:41] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[2016-11-21 09:59:41] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[2016-11-21 09:59:41] 	at java.lang.Thread.run(Thread.java:745)

submodule support

At the moment, versionDetails() fails when run against a submodule:

org.eclipse.jgit.api.errors.RefNotFoundException: Ref HEAD can not be resolved

Caused by: java.lang.NullPointerException
        at com.palantir.gradle.gitversion.VersionDetails.descriptionIsPlainTag(VersionDetails.java:81)
        at com.palantir.gradle.gitversion.VersionDetails.getLastTag(VersionDetails.java:94)
        at build_7orv6hikjrwy1ujlilpcudjcn.run(<path_to_submodule...>/build.gradle:13)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
        ... 102 more

To remarks:
First, VersionDetails.descriptionIsPlainTag():81 should check if null is not coming from description(). The null return value can occur if the repository is empty.

Second, if I am not mistaken, JGit handles submodules differently from git repositories.

Can't use version 0.11.0

When using the instructions on provided on gradle shown below:

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'gradle.plugin.com.palantir.gradle.gitversion:gradle-git-version:0.11.0'
    }
}
apply plugin: 'com.palantir.git-version'

It throws the following error:

> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve org.eclipse.jgit:org.eclipse.jgit:4.5.2.201704071617-r.
     Required by:
         :TheFacade:unspecified > gradle.plugin.com.palantir.gradle.gitversion:gradle-git-version:0.11.0
      > Could not resolve org.eclipse.jgit:org.eclipse.jgit:4.5.2.201704071617-r.
         > Could not get resource 'https://plugins.gradle.org/m2/org/eclipse/jgit/org.eclipse.jgit/4.5.2.201704071617-r/org.eclipse.jgit-4.5.2.201704071617-r.pom'.
            > Could not GET 'https://plugins.gradle.org/m2/org/eclipse/jgit/org.eclipse.jgit/4.5.2.201704071617-r/org.eclipse.jgit-4.5.2.201704071617-r.pom'.
               > Remote host closed connection during handshake

Inconsistent git describe

What happened?

When running the plugin in a project cloned after a push force the following error is returned

> Inconsistent git describe: native was 63864dd and jgit was v19.09.3-1-g63864dd. Please report this on github.com/palantir/gradle-git-version 

gitHash returns 'unspecified'

I have a git repository. At the moment it has no tags. I would still expect git hash to return the HEAD object hash, but instead it returns 'unspecified'.

Disable appending 'dirty' status

Is it possible to disable appending 'dirty' status easier that by code below?

def details = versionDetails()
version = details.lastTag + (details.commitDistance.toString() != '0' ? ('-' + details.commitDistance) : '')

Plugin with id 'com.palantir.git-version' not found, while using internally hosted artifactory.

I would like to use Gradle Git-Version 0.4.2

I am trying to use the plugin from internally hosted artifactory instead of https://plugins.gradle.org/m2/ as described in the build script snippet for use in all Gradle versions as per the note at https://plugins.gradle.org/plugin/com.palantir.git-version/0.4.2

Step 1: I have loaded the plugin jar to internal artifactory.
https://testrepo.com/artifactory/gradle-plugin/gradle/plugin/com/palantir/gradle/gitversion/gradle-git-version/0.4.2/gradle-git-version-0.4.2.jar

Step 2:
In my gradle.properties I have

artifactory_3PpluginsUrl=https://testrepo.com/artifactory/gradle-plugin

In my build.gradle I have

buildscript {
  repositories {
    maven {
      url "${artifactory_3PpluginsUrl}" 
    }
  }
  dependencies {
    classpath "gradle.plugin.com.palantir.gradle.gitversion:gradle-git-version:0.4.2"
  }
}
apply plugin: "com.palantir.git-version"

Step 3:
Upon execution, I get

* What went wrong:
A problem occurred evaluating root project 'EvalProjUtil'.
> Plugin with id 'com.palantir.git-version' not found.

I believe it is downloading the dependency

…
Unable to locate local Maven repository.
Download https://testrepo.com/artifactory/gradle-plugin/gradle/plugin/com/palantir/gradle/gitversion/gradle-git-version/0.4.2/gradle-git-version-0.4.2.pom
Download https://testrepo.com/artifactory/gradle-plugin/gradle/plugin/com/palantir/gradle/gitversion/gradle-git-version/0.4.2/gradle-git-version-0.4.2.jar
Compiling build file 'C:\codeBase\EvalProjUtil\build.gradle' using BuildScriptTransformer.

Nested .gitignore can cause jgit to incorrectly think stuff is dirty.

What happened?

My project used to have .gitignore files in each sub project.
They looked like this:

.gradle/
/build/
/log/
/var/log/
src/gen

During publishing, artifacts would attempt to be published as dirty, even though git status returned no changes.

I then moved all the rules from gitignores into a single git ignore at the top level of the project.

*/log/
*/var/log/
*/build
*/src/gen
.gradle

This ended up fixing the issue. So either jgit doesn't like nested git ignores, or it doesn't like the fact that I had a leading '/' in the rules. Possibly a bug?

What did you want to happen?

Inconsistent git describe during `rebase --exec`

It seems that the way gradle-git-version calculates native description makes assumptions that don't always hold. I expected it was just using git describe --tags --first-parent, but that works just fine:

$ git rebase --exec 'git describe --tags' develop
Executing: git describe --tags
2.71.0-30-g4bdd087aa
Executing: git describe --tags
2.71.0-31-g028a32eb8
Executing: git describe --tags
2.71.0-32-g26ccc19be
Executing: git describe --tags
2.71.0-33-g7e8a0d669
Executing: git describe --tags
2.71.0-34-g693f9688d
Executing: git describe --tags
2.71.0-35-g42549d503
Executing: git describe --tags
2.71.0-36-g2e8b418fc
Executing: git describe --tags
2.71.0-37-g2055391f7
Executing: git describe --tags
2.71.0-38-g0363cc265
Executing: git describe --tags
2.71.0-39-g9d79059fe
Executing: git describe --tags
2.71.0-40-g9fdd91a56
Executing: git describe --tags
2.71.0-41-g6957552f4
Successfully rebased and updated refs/heads/jl/foo.
 $ git rebase --exec './gradlew printVersion' develop
Executing: ./gradlew printVersion

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Volumes/git/foo/build.gradle' line: 47

* What went wrong:
A problem occurred evaluating root project 'foo'.
> Inconsistent git describe: native was 4bdd087 and jgit was 2.71.0-30-g4bdd087. Please report this on github.com/palantir/gradle-git-version

Handle "v" in version tags

Many projects, and recommended versionning model of Github, prepend their version git tags with a v, so something like v1.2.3, but this tag should not present in artifacts, especially anything sent to a Maven repository.

Could it be possible that gitVersion() does NOT return the prepended v?

versionDetails() should include date of the commit

I'm currently doing something like this:

def gitDate() {
    return 'git show -s --format=%cd --date=short'.execute().text.trim()
}
version "${gitDate()}-${gitVersion()}"

This gives me a rough idea of the age of each version. It would be great if I could do this without having to call out to git myself.

Expose author, date & commit message in version details

What happened?

I noticed that several important pieces of information are missing in the VersionDetails object:

  • the author of the commit (name, email)
  • the date & time of the commit
  • the commit message

Basically, all the things reported by git log.

What did you want to happen?

I'd like to see those included in the VersionDetails object.

FR: isRelease boolean on VersionDetails

I frequently see logic in other gradle files that is conditional on whether the project is 'released' or still 'under development':

def isRelease = (project.version.toString() ==~ /[0-9]+(\.[0-9]+)+((-(beta|rc)[0-9]{1,2})(\.[0-9])?)?/)
dockerPush.onlyIf { isRelease }

To avoid duplicating this regex, let's add a convenience boolean to the VersionDetails object, allowing us to write:

dockerPush.onlyIf { gitVersion().isRelease }

An exception occurred applying plugin request [id: 'com.palantir.git-version', version: '0.12.2']

What happened?

I get following error message when executing gradle:

  • What went wrong:
    An exception occurred applying plugin request [id: 'com.palantir.git-version', version: '0.12.2']

Failed to apply plugin [id 'com.palantir.git-version']
java.lang.NullPointerException (no error message)

In our build.gradle following line has been present:
plugins {
id 'com.palantir.git-version' version '0.12.2'
}

When I change to version '0.12.1' everything works fine. For my collegues version '0.12.2' works, but we haven't found any misconfiguration.

I am using following configuration:

Gradle 6.0

Build time: 2019-11-08 18:12:12 UTC
Revision: 0a5b531749138f2f983f7c888fa7790bfc52d88a

Kotlin: 1.3.50
Groovy: 2.5.8
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 1.8.0_141 (Oracle Corporation 25.141-b15)
OS: Windows 10 10.0 amd64

git version 2.23.0.windows.1.

Any ideas, how I can resolve this issue or at least find the root cause? Tanks in advance!

Cannot figure out how to invoke gitVersion() from Kotlin DSL

I'm in the process of converting our build scripts to use the Kotlin DSL and where previously I could just invoke gitVersion() from my Groovy script, I can't figure out the equivalent in Kotlin.

I'm applying the plugin with:

plugins {
    id("com.palantir.git-version") version "0.12.0-rc2"
}

In groovy, it'd then just call gitVersion() but here I get "Unresolved reference: gitVersion"

Apologies that this isn't really an issue with the gradle-git-version plugin itself, but this is the only plugin I'm using that "adds ... methods to the target project" and I've been completely unable to find other examples of how to access those.

first-parent problems

Since #46 was added, my builds are all messed up now.

We push code from development, to qc, to staging, and finally production. We add a tag when we're ready to increment the version number in development. That gets merged through the other branches.

git describe --first-parent -tags returns:
on my development branch: 0.10.0-51
on my qc branch: 0.3.0-107
on my staging branch: 0.3.0-76
on my release branch: 0.3.0-71

The latest tag in my development branch is 0.12.0. But using --first-parent, it doesn't show up at all.
When I merge code form development to QC, the new version is not picked up at all.

I'm going to have to roll back to an older version of the plugin (was using 0.5.2, which hopefully will still work), unless someone can explain how I can fix all my tags so that they will show up and work correctly across branches.

The purpose of this ticket is to request that either a CHANGELOG file be added to the project, or at the least notice in the README when potentially build breaking changes like this are made.

can not find in gradle pulgin repository

plugins {
id "java"
id "idea"
id "maven"
id "maven-publish"
id "com.jfrog.bintray" version "1.7"
id "com.palantir.git-version" version "0.5.2"
}

  • What went wrong:
    Plugin [id: 'com.palantir.git-version'] was not found in any of the following sources:
  • Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
  • Gradle Central Plugin Repository (plugin dependency must include a version number for this source)
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Returns "unspecified" on one repo

This works on two repositories, but on a third, always gives "unspecified". It's finding the repository, and git describe returns a tag/hash normally.

I'm not sure how to troubleshoot this (it's a private repository). I can see that it's finding .git and reading it, and if I copy the not-working project inside the working repository it does work, so it does seem to be something about the repository that it doesn't like. I'm not familiar with git internals to dig into it...

Unable to use plugin per readme

Can't use:

plugins {
    id 'com.palantir.git-version' version '<current version>'
}

Have to use the oldschool buildscript {} method.

Add support for long format on all builds.

I would like to be able to always have the long format for my version. Right now, if I am on a tag then the version is named after the tag. If I am not on a tag a suffix is added. I would like to be able to always have the suffix, regardless of whether I am on a tag or not.

This behavior can be achieved via setLong on the JGit DescribeCommand.

Create some kind of summary/toString method

Would be useful to have some kind of summaries methods for usage in the build script.

def details = versionDetails()
details.toString() //
details.shortSummary() //host, user, branch, revision, comment
details.summary() //host, user, branch, revision, comment, <something else>

Change plugin to match behavior of "git describe --first-parent"

Currently, the output of gradle-git-version matches the output of git describe. Although this is fine in the common case, it's often not the desired behavior if merge commits exist.

For example, consider the following case:

  • Mainline branch has some tag (1.0.0-dev) and development is proceeding normally
  • Some other branch (for example, 1.0.0-hotfix) is merged into the mainline branch
  • gradle-git-version is run on the mainline branch

In this scenario, we typically want the output to still be 1.0.0-dev-*. However, because git describe returns the nearest ancestor tag, the merge causes 1.0.0-hotfix to be found as a parent tag that is "closer" to the commit than 1.0.0-dev, so you get 1.0.0-hotfix-* instead.

The fix would be to match the behavior of git describe --first-parent instead -- this command only considers the first parent commit for merge commits, and would cause this to work correctly. I believe that this is almost always the desired behavior.

jgit fails on shallow clone

I'm getting this error:

> Inconsistent git describe: native was 8.3-pre and jgit was null. Please report this on github.com/palantir/gradle-git-version

Running with debug gets me a loong stack trace but the top of it looks like:

17:18:18.682 [DEBUG] [com.palantir.gradle.gitversion.JGitDescribe] JGit describe failed with {}
org.eclipse.jgit.errors.MissingObjectException: Missing commit 09d0457984dcf100a07e16da5bda493249ba3ce8
        at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:159)
        at org.eclipse.jgit.revwalk.RevWalk.getCachedBytes(RevWalk.java:903)
        at org.eclipse.jgit.revwalk.RevCommit.parseHeaders(RevCommit.java:155)
        at org.eclipse.jgit.revwalk.RevWalk.parseHeaders(RevWalk.java:1012)
        at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:861)
        at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:772)
        at com.palantir.gradle.gitversion.JGitDescribe.revList(JGitDescribe.java:77)
        at com.palantir.gradle.gitversion.JGitDescribe.describe(JGitDescribe.java:36)
        at com.palantir.gradle.gitversion.VersionDetails.expensiveComputeRawDescription(VersionDetails.java:64)
        at com.palantir.gradle.gitversion.VersionDetails.description(VersionDetails.java:50)
        at com.palantir.gradle.gitversion.VersionDetails.getVersion(VersionDetails.java:30)
        at com.palantir.gradle.gitversion.GitVersionPlugin$1.doCall(GitVersionPlugin.java:22)

This git repo was checked out with:

git clone <url> --branch <branchname> --depth 1

(it's a legacy project, recently - just now - converted to gradle; cloning the whole thing is huge, i wanted to do a minimal checkout.)

I had an earlier error where gitVersion() itself was returning null, causing a later error while writing a manifest, so I created a tag, then I get this.

The commit object mentioned as being missing in the above stacktrace is the penultimate one, ie: the one before the most recent, and therefore as I used --depth 1 it wasn't fetched. So I tried it again with --depth 2 and sure enough it all worked; in fact it worked without me needing to create that tag to have git describe have something to report. So I have a solution for myself, but this does look like a bug.

Unknown option 'first-parent'

It seems that the gradle-git-version plugin requires a newer version of git that I have :(

This worked before the jgit -> git cli change, wonder if its possible to detect this and not use this flag?

error: unknown option `first-parent'
usage: git describe [options] <committish>*
   or: git describe [options] --dirty

    --contains            find the tag that comes after the commit
    --debug               debug search strategy on stderr
    --all                 use any ref in .git/refs
    --tags                use any tag in .git/refs/tags
    --long                always use long format
    --abbrev[=<n>]        use <n> digits to display SHA-1s
    --exact-match         only output exact matches
    --candidates <n>      consider <n> most recent tags (default: 10)
    --match <pattern>     only consider tags matching <pattern>
    --always              show abbreviated commit object as fallback
    --dirty[=<mark>]      append <mark> on dirty working tree (default: "-dirty")

Incorrectly marking builds as dirty

gradle-git-version is incorrectly marking my builds as dirty. After some experimentation, I discovered adding git status to circle.yml immediately before the broken build magically fixes it. I then ls-ed the entire workspace before and after git status, and discovered the .git/index file is being updated. According to https://www.kernel.org/pub/software/scm/git/docs/technical/racy-git.txt, the index file is maintained lazily, and git needs to verify the state of the world when determining the status. Presumably jgit is just a broken git implementation in this regard?

Add switch to use only annotated tags

The first, called gitVersion(), runs git describe to determine a version string. It behaves exactly as git describe method behaves, except that when the repository is in a dirty state, appends .dirty to the version string.

I think that's wrong. Your gitVersion() runs git describe --tags and not git describe

Wouldn't it be good to have a switch on the versionDetails() function to indicate it should run only against annotated tags?

For example default behaviour prevents me adding custom tags. If I have tag v1.0 and then add a tag some-pointer the distance will be calculated against that latter one. If the v1.0 would be an annotated, it would work better I think.

Of course a workaround would be to use prefixes but that's not exactly the same

Version is Wrong when non-version Tags exist

This plugin works great when only version specific tags exist. If there are other tags in the repo, then it doesn't work properly, for example it would created featureX-5-g93f233e1 if someone tagged a commit with featureX.

Perhaps this plugin could define (or better yet, allow users to define) a prefix for which tags it considers to be tags with versions in them. For example if v were used, then a valid version tag would be v0.1.

Allow users to get commit count

Currently gitVersion() just returns a string, but it could be useful if it returned an object that allowed you to get the commit count, hash, tag, etc. Additionally, it might be good to allow users to get commit count since latest tag or total commit count.

[Feature] Support for generating Android versionCode

Hi,

Android requires versionCode to be a unique increasing integer.

I'm using the following command to calculate it from git:

git rev-list --tags --no-walk --count

I thought it would be great to have something similar in versionDetails:

versionDetails.versionCode

What do you think about that ?

Cheers.

commitDistance inconsistent with 'git describe --tags'

When looking at the following history:

selection_311

'git describe --tags' will show v0.1-7-g74a4d6a, while gradle-git-version's commitDistance is instead 1. This is because the history is considered with the semantics as if --first-parent were passed to git describe ().

This seems to have been intentional (#48, https://github.com/palantir/gradle-git-version/blob/develop/src/main/java/com/palantir/gradle/gitversion/JGitDescribe.java#L61, https://github.com/palantir/gradle-git-version/blob/develop/src/test/java/com/palantir/gradle/gitversion/JGitDescribeTest.java#L193), but I think it'd be great to have this more consistent with git describe --tags (or even configurable).

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.