Skip to content

Instantly share code, notes, and snippets.

@jmfayard
Created September 5, 2018 10:48
Show Gist options
  • Select an option

  • Save jmfayard/d17c9142f065ea7d5dbae9f359372b39 to your computer and use it in GitHub Desktop.

Select an option

Save jmfayard/d17c9142f065ea7d5dbae9f359372b39 to your computer and use it in GitHub Desktop.
Custom task with gradle kotlin buildSrc
// app/build.gradle
task updatewhatsnew << {
GooglePlay.updateWhatsNew(project.projectDir, niceVersion)
}
tasks.whenTaskAdded { task ->
if (task.name == "publishListingProductionRelease") {
task.dependsOn updatewhatsnew
}
}
// buildSrc/build.gradle.ktsbuildSrc/build.gradle.kts
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}
dependencies {
//...
}
// buildSrc/src/main/java/GooglePlay.kt
import java.io.File
object GooglePlay {
@JvmStatic
fun updateWhatsNew(projectDir: File, version: String) {
val files: List<File> = listOf(
"src/production/play/en-US/listing/whatsnew-alpha",
"src/production/play/en-US/whatsnew",
"src/production/play/en-US/whatsnew-alpha"
).map { projectDir.resolve(it) }
val fileContent = "KartaunBele $version"
for (file in files) {
check(file.canWrite()) { "Cannot write on ${file.absolutePath}" }
println("Updating ${file.absolutePath} with content [$fileContent]")
file.writeText("KartaunBele $version")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment