researchgate / gradle-release

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

Enhance documentation for Kotlin gradle build scripts #281

Open lexxy23 opened 5 years ago

lexxy23 commented 5 years ago

The documentation and way the plugin currently works is optimized only for Groovy. Can you show or state how I can make this plugin works using a kotlin build script (build.gradle.kts)?

Just to be sure: this is not a bug but some kind of documentation request.

Hillkorn commented 5 years ago

Didn't tried it out it kts build files yet but makes sense to add it to the README.

arashbi commented 5 years ago

I was trying to do the same thing. Got so far as to configure git. But simply using git {...} inside release doesn't work. What is the workaround?

pun-ky commented 5 years ago

the only existing workaround is to separate release {} section into other groovy build script file


plugins {
   id 'net.researchgate.release' version '2.6.0'
}

apply(from = "release.gradle")
release {
    git {
        // ...
    }
}
alex-arana commented 5 years ago

Another workaround is to invoke groovy dynamic method reception directly:

release {
    with (propertyMissing("git") as GitAdapter.GitConfig) {
        requireBranch = """master|develop|release\/.+"""
    }
}
jairovsky commented 5 years ago

Building on top of Alex's tip, you can use this snippet to create a DSL:

fun ReleaseExtension.git(configureFn : GitAdapter.GitConfig.() -> Unit) {
    (propertyMissing("git") as GitAdapter.GitConfig).configureFn()
}

Now you can use release { git {} } in kotlin just as you would in groovy.

Vampire commented 5 years ago

Instead of propertyMissing which tightly couples to implementation details, you can also use getProperty.

I had

release {
    val gitConfig = getProperty("git") as GitConfig
    gitConfig.signTag = true
}

or

release {
    (getProperty("git") as GitConfig).apply {
        signTag = true
    }
}

before I switched to

fun ReleaseExtension.git(configure: GitConfig.() -> Unit) = (getProperty("git") as GitConfig).configure()
alex-arana commented 2 years ago

Finally, none of the workarounds to configure Git Adapter attributes is necessary anymore with the release of plugin version 3.0.0.

According to the Kotlin DSL documentation this is all that's needed to configure Git Adapter attributes:

configure<ReleaseExtension> {
    with(git) {
        requireBranch = "master"
    }
}

Ticket can thus be closed.