Slackbot
03/29/2023, 1:40 PMVampire
03/29/2023, 2:03 PMVampire
03/29/2023, 2:04 PMkotlin-dsl
in build scripts and precompiled script plugins than general plugin development in Kotlin. 😉Luc-Antoine Girardin
03/29/2023, 2:18 PMLuc-Antoine Girardin
03/29/2023, 2:28 PMVampire
03/29/2023, 2:29 PMLuc-Antoine Girardin
03/29/2023, 2:33 PMpublic open class MyTask: DefaultTask() {
@Option(option = "param", description = "...")
public var param: String = ""
@set:Option(option = "param2", description = "...")
public var param2: String = ""
@Option(option = param3, description = "...")
public fun setParam3(value: String) { ... }
}
Luc-Antoine Girardin
03/29/2023, 2:40 PM@OutputFile
public val outputFile: RegularFileProperty = project.objects.fileProperty().convention(
RegularFile { File("...") }
)
Luc-Antoine Girardin
03/29/2023, 2:51 PM@Option
Vampire
03/29/2023, 2:51 PMRegularFile
like that. It just looks like a functional interface, but you cannot do it like that.
Regarding the option, iirc, I'd recommend you make it a val
and Property<String>
and then annotate the getter with @get:Option
Vampire
03/29/2023, 2:52 PMabstract
, then you don't need to initialize them, but Gradle will decorate it accordingly for youLuc-Antoine Girardin
03/29/2023, 2:52 PM@Option
was working in the included build, but I was calling it from the projectLuc-Antoine Girardin
03/29/2023, 2:54 PMRegularFile
? object : RegularFile { override... )
?Vampire
03/29/2023, 3:09 PMlayout.buildDirectory.file("foo")
.
Or to set a RegularFileProperty
you can also give it a File
if you have one.
But make sure to never anywhere call the File
constructor with a relative path.
That is bad in almost all situations, not only in a Gradle build, because it depends on the current working directory of the user.
And in case of a Gradle build that is often the project directory, but this is not guaranteed and not always the case.
You just make the build flaky and unreliable with that.
layout.projectDirectory.file("foo")
is for example better.Luc-Antoine Girardin
03/29/2023, 3:22 PM