ajoberstar / reckon

Infer a project's version from your Git repository.
Apache License 2.0
187 stars 28 forks source link

Is there a sample of how one can use this plugin? #66

Closed roguexz closed 6 years ago

roguexz commented 6 years ago

I was trying to figure out what the initial version of the project should be set to. I created a tag called 0.0.0 and added the plugin without any version details. But that failed with the following error.

No signature of method: org.ajoberstar.reckon.gradle.ReckonPlugin$DelayedVersion.trim() is applicable for argument types: () values: []

Here is how I am using the plugin,

plugins {
    id 'org.ajoberstar.grgit' version '2.1.1'
    id 'org.ajoberstar.reckon' version '0.4.0'
}

apply plugin: 'java'

group = 'xxxxxx'
//version = '0.0.0'

reckon {
    normal = scopeFromProp()
    // preRelease = snapshotFromProp()
}

task printVersionDetails() {
    doLast() {
        println 'Project version is set to: ' + project.getVersion()
    }
}

gradle printVersion -Preckon.scope=patch

Can you please tell me how I should use the plugin? I am a little lost and not sure where the version should be defined.

Environment

Gradle 4.6
Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_162 (Oracle Corporation 25.162-b12)
OS:           Mac OS X 10.13.3 x86_64
ajoberstar commented 6 years ago

There are a few things going on here:

I was trying to figure out what the initial version of the project should be set to. I created a tag called 0.0.0 and added the plugin without any version details.

There's no need to have any initial tags. Reckon will fall back to 0.0.0 as a base and increment from there. Adding a 0.0.0 should not cause any issues though.

No signature of method: org.ajoberstar.reckon.gradle.ReckonPlugin$DelayedVersion.trim() is applicable for argument types: () values: []

This error implies to me that something in your build is assuming project.version is a String, when Gradle technically treats it as an Object. Someone who wants a String version should be (either explicitly or implicitly) calling toString() on it. Reckon relies on this in order to delay version inference as late as possible.

Is the example build file you provided complete? I would expect that a reckon {} block without a preRelease specified should cause an error. I'm also not seeing anything that calls trim(), but there must be something in your build or a plugin you use that does so. Reckon does not call trim() anywhere in the Gradle plugin.

roguexz commented 6 years ago

Interesting. The snippet is not complete, I can try removing the other plugins to see what is causing the issue. Thank you again for your help. Let me test it out and confirm.

roguexz commented 6 years ago

Ack. The issue was with another plugin. After removing it, I can see that it is defaulting to 0.0.0. Next question that I have is, why is the minor version not incrementing when using the exact same command as there in the docs.

gradle print -Preckon.scope=minor -Preckon.stage=milestone

The tag is present in the local repository and has not been pushed to the remote (I am still testing the plugin out). Does the plugin look at tags present on the remote? Or on the ones checked out locally?

roguexz commented 6 years ago

Never mind .. Had to debug through the code to figure out what was happening. I had made local changes (not yet committed) and was hoping to see the version number change. I am making use of the snapshot strategy and thought I would be seeing the version number increment, because I had uncommitted files. Do you have any suggestions on how something like that can be worked with your plugin?

ajoberstar commented 6 years ago

I haven't implemented support for detecting uncommitted files, but I'll open an issue for that. That was a feature of gradle-git, so it would be good to have here too.

roguexz commented 6 years ago

Thank you so much. Should we close this issue then?

roguexz commented 6 years ago

BTW, I see that grgit is available on MVN Central, but not reckon. Is that intentional? I am trying to bake reckon in to a plugin of mine (which enforces certain rules pertaining to my org) which is when I noticed that I got only half the files 😄 ... I will configure the BT repo, but just wanted to let you know.

ajoberstar commented 6 years ago

Yeah, we can close this now if we've covered all of your questions.

I've only published to JCenter for the last couple years (you may notice that grgit on Maven Central is from 2016). Maven Central has more picky publishing rules, and I didn't want to deal with them when I broke the gradle-git plugin up. Not ruling out adding them in the future, but for now JCenter is the place to look.