Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to newest jgitver, gradle version #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ build/
src/test/integration/test/.git/
src/test/integration/test/build/
src/test/integration/test/.gradle/
src/test/integration/test/build.gradle
src/test/integration/test/build.gradle.kts
src/test/integration/test/content
.idea/
*.iml
*.iml

167 changes: 70 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,28 @@ In order to find the latest version published of [gradle-jgitver-plugin](https:/

see the project [build.gradle.kts](build.gradle.kts) to see how the project is using itself to manage its own versions.

Find latest version of the plugin: [click here](https://plugins.gradle.org/plugin/fr.brouillard.oss.gradle.jgitver)

### Usage for modern gradle versions _(>= 2.1)_
### Add the plugin

```
plugins {
id "fr.brouillard.oss.gradle.jgitver" version "0.9.1"
}
```

### Usage for all gradle versions _(including < 2.1)_
```
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.fr.brouillard.oss.gradle:gradle-jgitver-plugin:0.9.1"
}
}
### Use it

Besides calculating a version automatically when running any gradle task, like `gradle build`, the plugin registers a
task `version` which you can call to print out the calculated version of your project:

apply plugin: 'fr.brouillard.oss.gradle.jgitver'
```
$ ./gradlew version

> Task :version
Version: 0.10.1-rc03-2-dirty

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
```

## Documentation

Expand All @@ -47,49 +43,11 @@ Finally have a look at the [configuration](#configuration) paragraph to have ful

![Gradle Example](src/doc/images/gradle-example.gif?raw=true "Gradle Example")

### Tasks

#### Version

Since 0.2.0 the plugin automatically registers a task `version` which you can call to print out the calculated version of your project:

```
$ ./gradlew version
:version
Version: 0.0.2-4

BUILD SUCCESSFUL

Total time: 5.769 secs
```

Before 0.2.0, in order to know the current version of your project, just print out the version in a task looking like the following:

```
task version {
doLast {
println 'Version: ' + version
}
}
```

then just call the task

```
$ ./gradlew version
:version
Version: 0.0.2-4

BUILD SUCCESSFUL

Total time: 5.769 secs
```

### Configuration

#### version >= 0.2.0
#### build.gradle

Starting from `0.2.0` it is possible to configure the plugin inside the `build.gradle`.
Optionally, configure the plugin inside the `build.gradle`.

~~~~
jgitver {
Expand All @@ -104,10 +62,10 @@ jgitver {
useGitCommitTimestamp true/false
useGitCommitID true/false
gitCommitIDLength integer
maxDepth integer ( >= 0.7.0)
maxDepth integer
nonQualifierBranches string (comma separated list of branches)
versionPattern string (only for PATTERN strategy, >= 0.6.0)
tagVersionPattern string (only for PATTERN strategy >= 0.6.0)
versionPattern string (only for PATTERN strategy)
tagVersionPattern string (only for PATTERN strategy)
policy { repeatable closure
pattern string (regexp with capturing group)
transformations array (array of string)
Expand All @@ -117,6 +75,37 @@ jgitver {

~~~~

#### build.gradle.kts

Optionally, configure the plugin inside the `build.gradle.kts`.

~~~~
jgitver {
strategy = fr.brouillard.oss.jgitver.Strategies.PATTERN | MAVEN | CONFIGURABLE
mavenLike = true/false (deprecated, use strategy instead)
policy = fr.brouillard.oss.jgitver.LookupPolicy.MAX | LATEST | NEAREST
autoIncrementPatch = true/false
useDistance = true/false
useDirty = true/false
useSnapshot = true/false
failIfDirty = true/false
useGitCommitTimestamp = true/false
useGitCommitID = true/false
gitCommitIDLength = integer
maxDepth = integer
nonQualifierBranches = "string" (comma separated list of branches)
versionPattern = "string" (only for PATTERN strategy)
tagVersionPattern = "string" (only for PATTERN strategy)
policy { repeatable closure
pattern = "string" (regexp with capturing group)
transformations array (array of string)
}
distanceCalculatorKind = fr.brouillard.oss.jgitver.impl.DistanceCalculator.CalculatorKind.FIRST_PARENT | LOG | DEPTH
}

~~~~

#### Defaults
If you do not provide such a configuration (or fill only partial configuration) the following defaults will be used
- _strategy_: `CONFIGURABLE`
- _mavenLike_: `false`
Expand All @@ -138,20 +127,7 @@ If you do not provide such a configuration (or fill only partial configuration)
- the pattern must be a regular Java [Pattern](https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html) string with one matching group
- distanceCalculatorKind: `FIRST_PARENT`

#### version < 0.2.0

Before `0.2.0` no configuration was possible.
The plugin used [jgitver](https://github.com/McFoggy/jgitver) with the following settings:

- _mavenLike_: `false`
- _autoIncrementPatch_: `true`
- _nonQualifierBranches_: `'master'`
- _useDistance_: `true`
- _useGitCommitId_: `false`

#### Configuration examples

##### provide specific branch policies
#### Example to provide specific branch policies

Given the following configuration
```
Expand All @@ -176,9 +152,9 @@ $ gradlew version
Version: 1.0.1-3-LOGINPAGE
```

### Metadatas
#### Add metadata

Since `0.3.0`, jgitver [Metadatas](https://github.com/jgitver/jgitver/blob/master/src/main/java/fr/brouillard/oss/jgitver/metadata/Metadatas.java#L25) are exposed via gradle extension properties using the Metadata name in lower case.
Jgitver [Metadatas](https://github.com/jgitver/jgitver/blob/master/src/main/java/fr/brouillard/oss/jgitver/metadata/Metadatas.java#L25) are exposed via gradle extension properties using the Metadata name in lower case.

For example, one could enhance it's jar Manifest with the git commit id using:

Expand All @@ -195,10 +171,10 @@ jar {
}
```

### Building on detached HEAD
#### Building on detached HEAD

When working on a __detached HEAD__, as often on CI environments behind a SCM webhook, no branch information exists anymore from git.
Since `0.4.1` it now possible to provide externally the branch information via a system property or an environment variable.
It is possible to provide externally the branch information via a system property or an environment variable.

- all operating systems/shells: `gradlew version -Djgitver.branch=mybranch`
- bash only (_zsh?_) one line: `JGITVER_BRANCH=mybranch && gradlew version`
Expand All @@ -212,32 +188,26 @@ Since `0.4.1` it now possible to provide externally the branch information via a
## Local build & sample test project

- `$ ./gradlew install version` will install the current version inside the local maven repository and will print the published version
- minimal test project `build.gradle` file
- minimal test project `build.gradle.kts` file
````gradle
buildscript {
repositories {
plugins {
id("fr.brouillard.oss.gradle.jgitver") version "0.9.1"
}
repositories {
mavenLocal()
}
dependencies {
classpath "fr.brouillard.oss.gradle:gradle-jgitver-plugin:0.3.2"
}
}
apply plugin: 'fr.brouillard.oss.gradle.jgitver'
````
- test project `build.gradle` file with Maven like versioning
- test project `build.gradle.kts` file with Maven like versioning
````gradle
buildscript {
repositories {
plugins {
id("fr.brouillard.oss.gradle.jgitver") version "0.9.1"
}
repositories {
mavenLocal()
}
dependencies {
classpath "fr.brouillard.oss.gradle:gradle-jgitver-plugin:0.3.2"
}
}
apply plugin: 'fr.brouillard.oss.gradle.jgitver'

jgitver {
mavenLike true
strategy = fr.brouillard.oss.jgitver.Strategies.MAVEN
}
````

Expand All @@ -246,10 +216,13 @@ Since `0.4.1` it now possible to provide externally the branch information via a
Some integration tests are available to make some manual trials/verifications of the plugin.

````
# first install it into the local maven repo, then read the current version into a variable,
# afterwards call it using the following schema:
# bash src/test/integration/test/build.sh CONTEXT JGITVER_GRADLE_VERSION EXPECTED_COMPUTED_VERSION
./gradlew install version
cd src/test/integration/test
./build.sh CONTEXT JGITVER_GRADLE_VERSION EXPECTED_COMPUTED_VERSION
# example ./build.sh tag-regexp 0.5.1-2 2.0.1-1
GRADLE_JGIT_VERSION=`gradle version | grep "Version" | awk '{print $2}'`
echo GRADLE_JGIT_VERSION
./src/test/integration/test/build.sh tag-regexp ${GRADLE_JGIT_VERSION} 2.0.1-1
````

## Linux environment for windows users
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pluginBundle {
}

dependencies {
implementation("fr.brouillard.oss:jgitver:0.12.0")
implementation("fr.brouillard.oss:jgitver:0.14.0")
}

java {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 0 additions & 3 deletions src/test/integration/contexts/distance-depth/jgitver.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jgitver {
distanceCalculatorKind = fr.brouillard.oss.jgitver.impl.DistanceCalculator.CalculatorKind.DEPTH
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jgitver {
distanceCalculatorKind = fr.brouillard.oss.jgitver.impl.DistanceCalculator.CalculatorKind.FIRST_PARENT
}
3 changes: 0 additions & 3 deletions src/test/integration/contexts/distance-log/jgitver.gradle

This file was deleted.

3 changes: 3 additions & 0 deletions src/test/integration/contexts/distance-log/jgitver.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jgitver {
distanceCalculatorKind = fr.brouillard.oss.jgitver.impl.DistanceCalculator.CalculatorKind.LOG
}
3 changes: 0 additions & 3 deletions src/test/integration/contexts/maven-like/jgitver.gradle

This file was deleted.

3 changes: 3 additions & 0 deletions src/test/integration/contexts/maven-like/jgitver.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jgitver {
strategy = fr.brouillard.oss.jgitver.Strategies.MAVEN
}
3 changes: 0 additions & 3 deletions src/test/integration/contexts/merged-branches/jgitver.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jgitver {
strategy = fr.brouillard.oss.jgitver.Strategies.CONFIGURABLE
}
3 changes: 0 additions & 3 deletions src/test/integration/contexts/policy-latest/jgitver.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jgitver {
policy = fr.brouillard.oss.jgitver.LookupPolicy.LATEST
}
3 changes: 0 additions & 3 deletions src/test/integration/contexts/policy-nearest/jgitver.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jgitver {
policy = fr.brouillard.oss.jgitver.LookupPolicy.NEAREST
}
4 changes: 0 additions & 4 deletions src/test/integration/contexts/tag-regexp/jgitver.gradle

This file was deleted.

4 changes: 4 additions & 0 deletions src/test/integration/contexts/tag-regexp/jgitver.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jgitver {
strategy = fr.brouillard.oss.jgitver.Strategies.PATTERN
regexVersionTag = "r(.*)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./build.sh v1.2-tags-regexp $JGITVER_GRADLE_PLUGIN_VERSION 1.2.3-1
4 changes: 0 additions & 4 deletions src/test/integration/contexts/v1.2-tags-regexp/jgitver.gradle

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jgitver {
strategy = fr.brouillard.oss.jgitver.Strategies.PATTERN
regexVersionTag = "v(1\\.2.*)"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jgitver {
strategy = fr.brouillard.oss.jgitver.Strategies.PATTERN
versionPattern = "\${v}-standard"
tagVersionPattern = "\${v}-tag"
}
Loading