Skip to content

Commit

Permalink
fix: version self-awareness class Info in :core
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Jul 13, 2023
1 parent 14eef66 commit fc47bf5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ project.findProperty("nodeVersion")?.let { it.toString() }?.takeIf { it.isNotBla
log("override NodeJS version: $it", LogLevel.LIFECYCLE)
}

subprojects {
afterEvaluate {
afterEvaluate {
subprojects {
version = rootProject.version
}
}
44 changes: 30 additions & 14 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io.gitlab.arturbosch.detekt.Detekt
import org.danilopianini.gradle.gitsemver.SemanticVersion
import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask
Expand All @@ -7,8 +8,22 @@ plugins {
id(libs.plugins.ktMpp.mavenPublish.get().pluginId)
}

val tuPrologPackage get() = rootProject.group.toString()
val tuPrologPackageDir get() = tuPrologPackage.replace('.', File.separatorChar)
val tuPrologPackage: String
get() = group.toString()

val tuPrologPackageDir: String
get() = tuPrologPackage.replace('.', File.separatorChar)

val infoKtFileContent: String
get() = """|package $tuPrologPackage
|
|object Info {
| const val VERSION = "$version"
| val PLATFORM: Platform by lazy { currentPlatform() }
| val OS: Os by lazy { currentOs() }
|}
|
""".trimMargin()

kotlin {
sourceSets {
Expand All @@ -21,21 +36,22 @@ kotlin {
val infoKtFile = kotlin.srcDirs.first().absoluteFile.resolve("$tuPrologPackageDir/Info.kt")

val createInfoKt by tasks.creating {
doFirst {
val version = version.toString()
val rootVersion = rootProject.version.toString()
require(version matches SemanticVersion.semVerRegex) {
"Invalid version of project ${project.name}: $version"
}
require(version == rootVersion) {
"Version of project ${project.name} ($version) does not match " +
"root project's one ($rootVersion)"
}
}
doLast {
infoKtFile.writeText(
"""
|package $tuPrologPackage
|
|object Info {
| const val VERSION = "${rootProject.version}"
| val PLATFORM: Platform by lazy { currentPlatform() }
| val OS: Os by lazy { currentOs() }
|}
|
""".trimMargin()
)
infoKtFile.writeText(infoKtFileContent)
}
outputs.file(infoKtFile)
outputs.upToDateWhen { infoKtFile.exists() && infoKtFile.readText().contains(version.toString()) }
}

tasks.matching { it.name.endsWith("sourcesJar", ignoreCase = true) }
Expand Down

0 comments on commit fc47bf5

Please sign in to comment.