For a year I've used the following code to copy my changelog to another directory, for Dev and Alpha flavors specifically (not Beta/Prod):
android.applicationVariants.configureEach {
if (name.toDefaultLowerCase().contains("dev") || name.toDefaultLowerCase().contains("alpha")) {
preBuildProvider.configure {
dependsOn("copyChangelog")
}
}
}
tasks.register<Copy>("copyChangelog") {
from("$rootDir/docs/CHANGELOG.md")
into("src/devsettings/assets")
rename("CHANGELOG.md", "DevSettingsChangelog.md")
doFirst {
// Delete the existing CHANGELOG.md in the destination directory
// This code can be removed again soon!
file("$destinationDir/CHANGELOG.md").delete()
}
}
Now I've upgraded to gradle 9.0, and I have to implement it a little differently.
I've also combined both sections in a single one, see below.
However, it doesn't compile Cannot infer type for type parameter 'FileTypeT'. Specify it explicitly.
androidComponents {
onVariants { variant ->
if (variant.flavorName !in setOf("dev", "alpha")) return@onVariants
val copyTaskName = "copy${variant.name.replaceFirstChar { it.titlecase() }}Assets"
val copyTask = project.tasks.register<Copy>(copyTaskName) {
from("$rootDir/docs/CHANGELOG.md")
into("src/devsettings/assets")
// into("${project.buildDir}/generated/assets/${variant.dirName}")
rename { "DevSettingsChangelog.md" }
}
variant.artifacts.use(copyTask)
.wiredWith { task -> task.destinationDir }
.toReplace(ArtifactKind.DIRECTORY, Artifact.Category.OUTPUTS, "MERGED_ASSETS")
}
}
This alternative for the last few lines of code doesn't work either:
variant.mergeResourcesProvider.configure {
dependsOn(copyTask)
}
What can I do to fix this?
Note:
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "9.0.1" }
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip