[Gradle, JS] Fix newFileProperty for gradle <5.0

This commit is contained in:
Ilya Goncharov
2020-01-30 12:30:41 +03:00
parent d2261f5491
commit 99d0fa0d29
2 changed files with 14 additions and 9 deletions
@@ -1 +1,3 @@
kotlin.tests.individualTaskReports=true
kotlin.tests.individualTaskReports=true
#because of dependency (kotlinx-html) which is not klib yet
kotlin.js.mode=legacy
@@ -40,15 +40,18 @@ internal fun <T> Project.optionalProvider(initialize: () -> T?): ReadOnlyPropert
// Before 5.0 fileProperty is created via ProjectLayout
// https://docs.gradle.org/current/javadoc/org/gradle/api/model/ObjectFactory.html#fileProperty--
internal fun Project.newFileProperty(initialize: (() -> File)? = null): RegularFileProperty =
if (isGradleVersionAtLeast(5, 0)) {
project.objects.fileProperty().apply {
if (initialize != null) {
set(provider { RegularFile(initialize) })
}
}
internal fun Project.newFileProperty(initialize: (() -> File)? = null): RegularFileProperty {
val regularFileProperty = if (isGradleVersionAtLeast(5, 0)) {
project.objects.fileProperty()
} else {
val projectLayoutClass = Class.forName("org.gradle.api.file.ProjectLayout")
val filePropertyMethod = projectLayoutClass.getMethod("fileProperty")
filePropertyMethod(project.layout) as RegularFileProperty
}
}
return regularFileProperty.apply {
if (initialize != null) {
set(provider { RegularFile(initialize) })
}
}
}