vivin / gradle-semantic-build-versioning

Gradle plugin to generate version-numbers and tags using semantic versioning
MIT License
85 stars 32 forks source link

NPE when no tag present in git log #104

Open radai-rosenblatt opened 5 years ago

radai-rosenblatt commented 5 years ago

on new(-ish) projects, where the git history has no tags to gen an initial version from, I get this when running ./gradlew printVersion. also happens for most other gradle commands

java.lang.NullPointerException: Cannot invoke method split() on null object
        at net.vivin.gradle.versioning.VersionUtils.incrementVersion(VersionUtils.groovy:228)
        at net.vivin.gradle.versioning.VersionUtils.determineIncrementedVersionFromTags(VersionUtils.groovy:185)
        at net.vivin.gradle.versioning.VersionUtils.determineVersion(VersionUtils.groovy:102)
        at net.vivin.gradle.versioning.VersionUtils$determineVersion.call(Unknown Source)
        at net.vivin.gradle.versioning.SemanticBuildVersion.toString(SemanticBuildVersion.groovy:157)
        at net.vivin.gradle.versioning.SemanticBuildVersioningPlugin$_apply_closure1.doCall(SemanticBuildVersioningPlugin.groovy:40)
        at org.gradle.util.ClosureBackedAction.execute(ClosureBackedAction.java:70)
ldiaz2-chwy commented 5 years ago

Im seeing the same issue

vivin commented 5 years ago

It should probably check to see whether there are any tags first before doing anything. This is definitely a bug.

vivin commented 5 years ago

@radai-rosenblatt What version of the plugin are you use, and what version of git? I checked the source and it looks like it does check to see if there are any tags at all, and if not, it will use the starting version.

vivin commented 5 years ago

@radai-rosenblatt @ldiaz2 do you guys have a sample repo where this is happening?

ldiaz2-chwy commented 5 years ago

i worked around it by setting a 0.0.0 tag and then it does not hit this error.

vivin commented 5 years ago

That's still pretty strange, given that it should automatically use the default version if it cannot find any tags. I wasn't able to duplicate this, so I'm closing this issue for now.

Felixoid commented 5 years ago

Hey @vivin. I've faced the same issue. The way to reproduce:

  1. Create a project and set it up, make a commit
  2. Tag the commit with, e.g., v0.0.1
  3. Try to run gradle tasks
  4. Do git commit --amend --no-edit
  5. Try to run gradle tasks again

Here is a state, which causes Cannot invoke method split() on null object

* 61767ac (HEAD -> gradle-debian) Update changelog for 0.0.1 release
| * 936da14 (tag: v0.0.1, origin/gradle-debian) Update changelog for 0.0.1 release
|/  
* a7e093f Build, publish and deploy the package

The setting startingVersion = '0.0.1' mitigates this, BTW

Felixoid commented 5 years ago

upd I use v 4.0.0 of the plugin

vitorog commented 5 years ago

Hi, I also encountered the same issue and created a repository that reproduces it: https://github.com/vitorog/gradle-semantic-build-versioning-bug

To reproduce it, just run on the master branch: ./gradlew printVersion (or any other task)

Steps that I took:

  1. Created the repository with the gradle files (with startingVersion = 1.0.0)
  2. Created a new branch (develop), added a new file to it (test.txt) and commited
  3. Executed: "./gradlew tag -PbumpComponent=patch -Prelease" on the develop branch
  4. Now, gradle tasks on the master branch fail with the NPE error in the original post

Additional info: Plugin version: 4.0.0 Git version: git version 2.22.0.windows.1 Gradle version: Gradle 5.3 Build time: 2019-03-20 11:03:29 UTC Revision: f5c64796748a98efdbf6f99f44b6afe08492c2a0

Kotlin: 1.3.21 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_212-release (JetBrains s.r.o 25.212-b4) OS: Windows 10 10.0 amd64

vivin commented 5 years ago

@vitorog Thanks for a working example. I will try to look at this as soon as I can.

broth-eu commented 4 years ago

@vivin Are there any news on it? Does some workaround exist?

jsmithpkp commented 4 years ago

I got passed this by making sure I was cloning the repository and not just fetching it. My guess is that fetch does not get the tags. I am using gitlab. Here is how to do it https://docs.gitlab.com/ee/ci/pipelines/settings.html.