Skip to content

Commit ed604ec

Browse files
authored
doc: add kotlin dsl example
1 parent 12a6c76 commit ed604ec

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,29 @@ This extension will set project versions, based on current **Git branch** or **G
2222

2323
### Add Plugin
2424

25-
add plugin to `buil.gradle` file
26-
25+
#### Groovy DSL `build.gradle`
2726
```groovy
2827
plugins {
2928
id 'me.qoomon.git-versioning' version '1.2.3'
3029
}
3130
```
3231

32+
#### Kotlin DSL `build.gradle.kts`
33+
```kotlin
34+
plugins {
35+
id("me.qoomon.git-versioning") version "1.2.3"
36+
}
37+
```
38+
3339
ℹ Consider [CI/CD](#cicd) section when running this plugin in a CI/CD environment
3440

3541
## Configure Extension
3642

3743
You can configure the final version format for specific branches and tags separately.
3844

39-
**Example:** `build.gradle`
45+
### Example Configuration
46+
47+
##### Groovy DSL `build.gradle`
4048
```groovy
4149
gitVersioning {
4250
branch {
@@ -56,6 +64,30 @@ gitVersioning {
5664
}
5765
}
5866
```
67+
68+
#### Kotlin DSL `build.gradle.kts`
69+
```kotlin
70+
import me.qoomon.gradle.gitversioning.GitVersioningPluginExtension.VersionDescription
71+
import me.qoomon.gradle.gitversioning.GitVersioningPluginExtension.CommitVersionDescription
72+
gitVersioning {
73+
branch(closureOf<VersionDescription> {
74+
pattern = "master"
75+
versionFormat = "\${version}"
76+
})
77+
branch(closureOf<VersionDescription> {
78+
pattern = "feature/(?<feature>.+)"
79+
versionFormat = "\${feature}-SNAPSHOT"
80+
})
81+
tag(closureOf<VersionDescription>{
82+
pattern = "v(?<tagVersion>[0-9].*)"
83+
versionFormat = "\${tagVersion}"
84+
})
85+
commit(closureOf<CommitVersionDescription>{
86+
versionFormat = "\${commit.short}"
87+
})
88+
}
89+
```
90+
5991
- *optional* `preferTags` global enable(`true`)/disable(`false`) prefer tag rules over branch rules if both match.
6092

6193
- `branch` specific version format definition.

0 commit comments

Comments
 (0)