diff --git a/build.gradle.kts b/build.gradle.kts index 1be4c8c..2fc93f4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,5 @@ import com.saveourtool.buildutils.* - plugins { kotlin("multiplatform") apply false id("com.saveourtool.buildutils.publishing-configuration") @@ -9,8 +8,6 @@ plugins { group = "com.saveourtool.okio-extras" -configureVersioning() - allprojects { repositories { mavenCentral() diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 1dec98c..ecb5a1b 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -11,6 +11,4 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22") implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:4.3.0") implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.5") - implementation("org.ajoberstar.reckon:reckon-gradle:0.18.3") - implementation("org.ajoberstar.grgit:grgit-core:5.2.2") } diff --git a/buildSrc/src/main/kotlin/com/saveourtool/buildutils/VersioningConfiguration.kt b/buildSrc/src/main/kotlin/com/saveourtool/buildutils/VersioningConfiguration.kt deleted file mode 100644 index 891b28e..0000000 --- a/buildSrc/src/main/kotlin/com/saveourtool/buildutils/VersioningConfiguration.kt +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Version configuration file. - */ - -package com.saveourtool.buildutils - -import org.ajoberstar.grgit.Grgit -import org.ajoberstar.reckon.gradle.ReckonExtension -import org.ajoberstar.reckon.gradle.ReckonPlugin -import org.gradle.api.GradleException -import org.gradle.api.Project -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure - -@Suppress("MISSING_KDOC_ON_FUNCTION", "MISSING_KDOC_TOP_LEVEL") -/** - * Configures how project version is determined. - * - * @throws GradleException if there was an attempt to run release build with dirty working tree - */ -fun Project.configureVersioning() { - apply() - - val isSnapshot = hasProperty("reckon.stage") && property("reckon.stage") == "snapshot" - configure { - calcScopeFromProp() - if (isSnapshot) { - // we should build snapshots only for snapshot publishing, so it requires explicit parameter - snapshots() - } else { - stages("alpha", "rc", "final") - } - calcStageFromProp() - } - - // to activate release, provide `-Prelease` or `-Prelease=true`. To deactivate, either omit the property, or set `-Prelease=false`. - val isRelease = hasProperty("release") && (property("release") as String != "false") - if (isRelease) { - val grgit = project.findProperty("grgit") as Grgit // grgit property is added by reckon plugin - val status = grgit.repository.jgit.status().call() - if (!status.isClean) { - throw GradleException( - "Release build will be performed with not clean git tree; aborting. " + - "Untracked files: ${status.untracked}, uncommitted changes: ${status.uncommittedChanges}" - ) - } - } - if (isSnapshot) { - val grgit = project.findProperty("grgit") as Grgit // grgit property is added by reckon plugin - // A terrible hack to remove all pre-release tags. Because in semver `0.1.0-SNAPSHOT` < `0.1.0-alpha`, in snapshot mode - // we remove tags like `0.1.0-alpha`, and then reckoned version will still be `0.1.0-SNAPSHOT` and it will be compliant. - val preReleaseTagNames = grgit.tag.list() - .sortedByDescending { it.commit.dateTime } - .takeWhile { - // take latest tags that are pre-release - !it.name.matches(Regex("""^v\d+\.\d+\.\d+$""")) - } - .map { it.name } - grgit.tag.remove { this.names = preReleaseTagNames } - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 40b753d..90ff521 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,52 @@ +import org.ajoberstar.reckon.core.Reckoner +import org.ajoberstar.reckon.core.ScopeCalculator +import org.ajoberstar.reckon.core.VersionTagParser +import org.ajoberstar.reckon.gradle.ReckonExtension + rootProject.name = "okio-extras" +plugins { + id("org.ajoberstar.reckon.settings") version "0.18.3" +} + includeBuild("gradle/plugins") include("okio-extras") + +extensions.configure { + setDefaultInferredScope("patch") + // to activate release, provide `-Prelease` or `-Prelease=true`. To deactivate, either omit the property, or set `-Prelease=false`. + val isRelease = extra.has("release") && extra["release"] != "false" + if (isRelease) { + val scopeCalculator = ScopeCalculator { inventory -> + if (inventory.isClean) { + calcScopeFromProp().calculate(inventory) + } else { + throw GradleException( + "Release build will be performed with not clean git tree; aborting." + ) + } + } + setScopeCalc(scopeCalculator) + } else { + setScopeCalc(calcScopeFromProp()) + } + val isSnapshot = extra.has("reckon.stage") && extra["reckon.stage"] == "snapshot" + if (isSnapshot) { + // we should build snapshots only for snapshot publishing, so it requires explicit parameter + snapshots() + } else { + stages("beta", "rc", Reckoner.FINAL_STAGE) + } + setStageCalc(calcStageFromProp()) + + // A terrible hack to remove all pre-release tags. Because in semver `0.1.0-SNAPSHOT` < `0.1.0-alpha`, in snapshot mode + // we remove tags like `0.1.0-alpha`, and then reckoned version will still be `0.1.0-SNAPSHOT` and it will be compliant. + val tagParser = VersionTagParser { tag: String -> + if (tag.matches(Regex("""^v\d+\.\d+\.\d+$"""))) { + VersionTagParser.getDefault().parse(tag) + } else { + java.util.Optional.empty() + } + } + setTagParser(tagParser) +}