Dariusz Kuc
02/07/2020, 2:57 AM@Input
@Option(option = "outputFileName", description = "target file name")
val outputFileName: Property<String> = project.objects.property(String::class.java)
@Suppress("UnstableApiUsage")
@Internal
@OutputFile
val outputFile: RegularFileProperty = project.objects.fileProperty()
How do I properly initialize the outputFile with the specified outputFileName?octylFractal
02/07/2020, 2:59 AMinit {} block + https://docs.gradle.org/current/javadoc/org/gradle/api/file/RegularFileProperty.html#convention-org.gradle.api.provider.Provider-?
a regular file can be constructed using https://docs.gradle.org/current/javadoc/org/gradle/api/file/ProjectLayout.htmlDariusz Kuc
02/07/2020, 3:02 AMinit {
outputFile = project.objects.fileProperty().fileValue(File(outputFileName.getOrElse("whatever")))
}
?octylFractal
02/07/2020, 3:02 AMoctylFractal
02/07/2020, 3:03 AMconvention(Provider<RegularFile>)octylFractal
02/07/2020, 3:04 AMoutputFile.convention { project.layout.projectDirectory.file(outputFileName.getOrElse("whatever")) }Dariusz Kuc
02/07/2020, 3:06 AMFile but got RegularFileoctylFractal
02/07/2020, 3:06 AMRegularFileoctylFractal
02/07/2020, 3:07 AMDariusz Kuc
02/07/2020, 3:07 AM@Internal
@OutputFile
val outputFile: RegularFileProperty = project.objects.fileProperty()
init {
outputFile.convention { project.layout.projectDirectory.file(outputFileName.getOrElse("whatever")) }
}Dariusz Kuc
02/07/2020, 3:08 AMDariusz Kuc
02/07/2020, 3:08 AMoctylFractal
02/07/2020, 3:08 AMDariusz Kuc
02/07/2020, 3:08 AMDariusz Kuc
02/07/2020, 3:09 AMDariusz Kuc
02/07/2020, 3:09 AMoctylFractal
02/07/2020, 3:09 AMoctylFractal
02/07/2020, 3:09 AMRegularFileProperty.convention uses RegularFile in 6.1.1Dariusz Kuc
02/07/2020, 3:09 AMoctylFractal
02/07/2020, 3:09 AMoctylFractal
02/07/2020, 3:10 AMDariusz Kuc
02/07/2020, 3:10 AMDariusz Kuc
02/07/2020, 3:12 AMDariusz Kuc
02/07/2020, 3:13 AMDariusz Kuc
02/07/2020, 3:45 AM{} vs value set ()octylFractal
02/07/2020, 3:46 AMoctylFractal
02/07/2020, 3:46 AMoctylFractal
02/07/2020, 3:46 AMDariusz Kuc
02/07/2020, 3:46 AMDariusz Kuc
02/07/2020, 3:46 AMoctylFractal
02/07/2020, 3:47 AMproject.provider()octylFractal
02/07/2020, 3:47 AMDariusz Kuc
02/07/2020, 3:47 AMDariusz Kuc
02/07/2020, 3:49 AMproject.provider { convention } ? didn't like itDariusz Kuc
02/07/2020, 3:50 AMDariusz Kuc
02/07/2020, 3:50 AMoctylFractal
02/07/2020, 3:50 AM{ ... } wrapped in project.provider, e.g. outputFile.convention(project.provider { ... })octylFractal
02/07/2020, 3:51 AMCallable via implicit Single-Abstract-Method (SAM) Conversion, then project.provider() converts that to a Provider, which outputFile.convention() can then takeDariusz Kuc
02/07/2020, 3:56 AMoctylFractal
02/07/2020, 3:57 AMoctylFractal
02/07/2020, 3:57 AMoctylFractal
02/07/2020, 3:58 AMoctylFractal
02/07/2020, 3:58 AMoutputFile.convetion(project.layout.projectDirectory.file(outputFileName))Dariusz Kuc
02/07/2020, 3:58 AMoctylFractal
02/07/2020, 3:58 AMoutputFileName to "whatever"octylFractal
02/07/2020, 3:58 AMgetOrElseDariusz Kuc
02/07/2020, 3:58 AMDariusz Kuc
02/07/2020, 4:00 AMDariusz Kuc
02/07/2020, 4:00 AMDariusz Kuc
02/07/2020, 4:00 AMDariusz Kuc
02/07/2020, 4:00 AMDariusz Kuc
02/07/2020, 4:00 AMDariusz Kuc
02/07/2020, 4:36 AM@OutputFile
val outputFile: Provider<RegularFile> = outputFileName.map { name -> project.layout.projectDirectory.file(name) }Dariusz Kuc
02/07/2020, 4:36 AM