Bernhard Posselt
09/23/2024, 9:13 AMThomas Broyer
09/23/2024, 9:18 AMRegularFileProperty
https://docs.gradle.org/current/userguide/lazy_configuration.html#working_with_files_in_lazy_propertiesBernhard Posselt
09/23/2024, 9:20 AMBernhard Posselt
09/23/2024, 9:21 AMBernhard Posselt
09/23/2024, 9:22 AMlayout.buildDirectory.file("release.zip")
this returns a Provider<RegularFile> not a RegularFilePropertyBernhard Posselt
09/23/2024, 9:23 AMBernhard Posselt
09/23/2024, 9:34 AMBernhard Posselt
09/23/2024, 9:36 AMgreeting.set("Hi")
greeting = "Hi"
these are mentioned as equivalent but the latter throws a Type mismatch: inferred type is String but Property<String> was expectedBernhard Posselt
09/23/2024, 9:37 AMBernhard Posselt
09/23/2024, 9:40 AMembedded-kotlin and kotlin-dsl plugins rely on features of Kotlin 1.9.24 that might work differently than in the requested version 2.0.20.Thomas Broyer
09/23/2024, 9:41 AMRegularFileProperty is for declaration; and the property can then be given a RegularFile, a Provider<RegularFile>, or even a File or Provider<File> (using the fileValue() and fileProvider() methodsBernhard Posselt
09/23/2024, 9:42 AMBernhard Posselt
09/23/2024, 9:42 AMtasks.register<Release>("release") {
dependsOn("package")
releaseZip = layout.buildDirectory.file("release.zip")
version.set(project.version.toString())
}Thomas Broyer
09/23/2024, 9:43 AMBernhard Posselt
09/23/2024, 9:43 AMBernhard Posselt
09/23/2024, 9:43 AMabstract class Release : DefaultTask() {
@get:InputFile
abstract var releaseZip: RegularFileProperty
@get:Input
abstract var version: Property<String>
@TaskAction
fun action() {
val zipFile = releaseZip.asFile.orNull
if (zipFile == null || !zipFile.exists()) {
throw IllegalStateException("Need an archive file")
}
println(version.get())
println(zipFile.absolutePath)
}
}Bernhard Posselt
09/23/2024, 9:44 AMThomas Broyer
09/23/2024, 9:44 AMThomas Broyer
09/23/2024, 9:47 AMBernhard Posselt
09/23/2024, 9:48 AMBernhard Posselt
09/23/2024, 9:48 AMBernhard Posselt
09/23/2024, 9:49 AMBernhard Posselt
09/23/2024, 10:01 AMThomas Broyer
09/23/2024, 10:05 AM.value() or .set() rather than = then.Bernhard Posselt
09/23/2024, 10:05 AMBernhard Posselt
09/23/2024, 10:08 AMThomas Broyer
09/23/2024, 10:08 AMRelease task should use val, not var!Bernhard Posselt
09/23/2024, 10:09 AMThomas Broyer
09/23/2024, 10:09 AM= syntactic sugar is then added by GradleBernhard Posselt
09/23/2024, 10:09 AMBernhard Posselt
09/23/2024, 10:09 AMThomas Broyer
09/23/2024, 10:10 AMVampire
09/23/2024, 10:27 AMVampire
09/23/2024, 10:28 AMorg.jetbrains.kotlin.assignment compiler plugin (mainly developed for this use-case though as far as I know 😄)Bernhard Posselt
09/23/2024, 10:28 AMBernhard Posselt
09/23/2024, 10:28 AMVampire
09/23/2024, 10:29 AMSupportsKotlinAssignmentOverloading, so any class annotated with that annotation can use this assignment overloading on val properties of that type.Vampire
09/23/2024, 10:29 AMVampire
09/23/2024, 10:29 AMVampire
09/23/2024, 10:30 AMBernhard Posselt
09/23/2024, 10:30 AMJavi
09/23/2024, 10:40 AMVampire
09/23/2024, 11:42 AMAssignmentExtension called assignment with which you can configure the annotations that mark supported types in your project.Vampire
09/23/2024, 11:45 AMSupportsKotlinAssignmentOverloading annotation, it is part of the Gradle public API as it is org.gradle.api.SupportsKotlinAssignmentOverloading.Vampire
09/23/2024, 11:46 AMsam-with-receiver and so on, simply apply the kotlin-dsl plugin which configures this compiler plugin, or configure the plugin yourself if you don't like to use the kotlin-dsl plugin for some reason.Javi
09/23/2024, 11:56 AMSure, it is usable in any Kotlin project I think.I mean, it is applied on simple kt files in buildSrc by default? I doubt it is applied so the equals overload will not work there
Vampire
09/23/2024, 12:15 PMkotlin-dsl plugin or manually configure the compiler plugin.
As I usually use included builds instead of buildSrc I don't remember the details, but it could even be that the kotlin-dsl plugin is applied automatically in buildSrc build.