53 lines
1.3 KiB
Groovy
53 lines
1.3 KiB
Groovy
|
String versionLine() { return " const val project = \"$project.version\"" }
|
||
|
File versionFile() { return project.file("src/commonMain/kotlin/dev/inmo/postssystem/features/common/common/Version.kt") }
|
||
|
|
||
|
void createVersionFile() {
|
||
|
String versionLine = versionLine()
|
||
|
File versionFile = versionFile()
|
||
|
versionFile.parentFile.mkdirs()
|
||
|
if (versionFile.exists()) versionFile.delete()
|
||
|
versionFile.createNewFile()
|
||
|
versionFile.text = """package dev.inmo.postssystem.features.common.common
|
||
|
|
||
|
/*
|
||
|
* THIS FILE HAS BEEN CREATED AUTOMATICALLY.
|
||
|
* DO NOT EDIT THIS FILE, ITS CONTENT WILL BE OVERWRITTEN
|
||
|
* WITH ANY NEW BUILD
|
||
|
*/
|
||
|
object Version {
|
||
|
$versionLine
|
||
|
}
|
||
|
"""
|
||
|
}
|
||
|
|
||
|
Boolean isVersionFileUpToDate() {
|
||
|
String versionLine = versionLine()
|
||
|
File versionFile = versionFile()
|
||
|
|
||
|
boolean upToDate = false
|
||
|
if (versionFile.exists()) {
|
||
|
versionFile.withReader { reader ->
|
||
|
String line
|
||
|
while ((line = reader.readLine()) != null && !upToDate) {
|
||
|
upToDate = line == versionLine
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return upToDate
|
||
|
}
|
||
|
|
||
|
task createVersionFile {
|
||
|
doLast {
|
||
|
createVersionFile()
|
||
|
}
|
||
|
outputs.upToDateWhen {
|
||
|
isVersionFileUpToDate()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if (!isVersionFileUpToDate()) {
|
||
|
createVersionFile()
|
||
|
}
|