researchgate / gradle-release

gradle-release is a plugin for providing a Maven-like release process for projects using Gradle
MIT License
859 stars 223 forks source link

versionPatterns support with Kotlin dsl #342

Open santbob opened 3 years ago

santbob commented 3 years ago

One of our projects is using Kotlin DSL instead of Groovy-based syntax and our Jenkins Paved path setup uses this release plugin. I need a way to convert

versionPatterns = [/(\d+)([^\d]*$)/: { Matcher m, Project p -> m.replaceAll("${(m[0][1] as int) + 1}${m[0][2]}") } ]

to a compatible Kotlin DSL version.

please suggest how to go about it.

cjaehnen commented 3 years ago

@santbob

I ran into a similar issue. I was able to solve it using the KotlinClosure2, which creates a Groovy closure that provides 2 parameters. I prefer to auto-increment the minor version automatically instead of the patch version, as most of my releases contain new features. Below is my release plugin configuration when running ./gradlew clean release -Prelease.useAutomaticVersion=true

release {
    versionPatterns = mapOf(
        // Increments 1.1.1 to 1.2.0-SNAPSHOT
        """[.]*\.(\d+)\.(\d+)[.]*""" to KotlinClosure2<Matcher, Project, String>({ matcher, project ->
            matcher.replaceAll(".${(matcher.group(0)[1]) + 1}.0")
        })
    )
    git {
        requireBranch = ""
        pushToRemote = "origin"
    }
}