[Gradle, JS] Task configuration avoidance with providers
This commit is contained in:
+16
-6
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
|||||||
import org.gradle.api.NamedDomainObjectContainer
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.plugins.BasePluginConvention
|
import org.gradle.api.plugins.BasePluginConvention
|
||||||
|
import org.gradle.api.provider.Provider
|
||||||
import org.gradle.api.tasks.Copy
|
import org.gradle.api.tasks.Copy
|
||||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||||
@@ -96,9 +97,9 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.entry = getByKind(
|
it.entry = getByKind(
|
||||||
kind,
|
kind,
|
||||||
compilation.productionLinkTask.outputFile,
|
compilation.productionLinkTask.map {it.outputFile},
|
||||||
compilation.developmentLinkTask.outputFile
|
compilation.developmentLinkTask.map{it.outputFile}
|
||||||
)
|
).get()
|
||||||
it.description = "start ${kind.name.toLowerCase()} webpack dev server"
|
it.description = "start ${kind.name.toLowerCase()} webpack dev server"
|
||||||
|
|
||||||
it.devServer = KotlinWebpackConfig.DevServer(
|
it.devServer = KotlinWebpackConfig.DevServer(
|
||||||
@@ -172,9 +173,9 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.entry = getByKind(
|
it.entry = getByKind(
|
||||||
kind,
|
kind,
|
||||||
compilation.productionLinkTask.outputFile,
|
compilation.productionLinkTask.map { it.outputFile },
|
||||||
compilation.developmentLinkTask.outputFile
|
compilation.developmentLinkTask.map { it.outputFile }
|
||||||
)
|
).get()
|
||||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
||||||
it.destinationDirectory = distribution.directory
|
it.destinationDirectory = distribution.directory
|
||||||
|
|
||||||
@@ -215,6 +216,15 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
BuildVariantKind.DEVELOPMENT -> debugValue
|
BuildVariantKind.DEVELOPMENT -> debugValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun <T> getByKind(
|
||||||
|
kind: BuildVariantKind,
|
||||||
|
releaseValue: Provider<T>,
|
||||||
|
debugValue: Provider<T>
|
||||||
|
): Provider<T> = when (kind) {
|
||||||
|
BuildVariantKind.PRODUCTION -> releaseValue
|
||||||
|
BuildVariantKind.DEVELOPMENT -> debugValue
|
||||||
|
}
|
||||||
|
|
||||||
override fun configureBuildVariants() {
|
override fun configureBuildVariants() {
|
||||||
buildVariants = project.container(BuildVariant::class.java)
|
buildVariants = project.container(BuildVariant::class.java)
|
||||||
buildVariants.create(PRODUCTION) {
|
buildVariants.create(PRODUCTION) {
|
||||||
|
|||||||
+6
-4
@@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.file.SourceDirectorySet
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||||
@@ -20,13 +22,13 @@ class KotlinJsIrCompilation(
|
|||||||
) : KotlinJsCompilation(target, name) {
|
) : KotlinJsCompilation(target, name) {
|
||||||
val productionLinkTaskName: String = linkTaskName(PRODUCTION)
|
val productionLinkTaskName: String = linkTaskName(PRODUCTION)
|
||||||
|
|
||||||
val productionLinkTask: KotlinJsIrLink
|
val productionLinkTask: TaskProvider<KotlinJsIrLink>
|
||||||
get() = (target.project.tasks.getByName(productionLinkTaskName) as KotlinJsIrLink)
|
get() = target.project.tasks.named(productionLinkTaskName) as TaskProvider<KotlinJsIrLink>
|
||||||
|
|
||||||
val developmentLinkTaskName: String = linkTaskName(DEVELOPMENT)
|
val developmentLinkTaskName: String = linkTaskName(DEVELOPMENT)
|
||||||
|
|
||||||
val developmentLinkTask: KotlinJsIrLink
|
val developmentLinkTask: TaskProvider<KotlinJsIrLink>
|
||||||
get() = (target.project.tasks.getByName(developmentLinkTaskName) as KotlinJsIrLink)
|
get() = target.project.tasks.named(developmentLinkTaskName) as TaskProvider<KotlinJsIrLink>
|
||||||
|
|
||||||
private fun linkTaskName(type: KotlinJsIrType): String =
|
private fun linkTaskName(type: KotlinJsIrType): String =
|
||||||
lowerCamelCaseName(
|
lowerCamelCaseName(
|
||||||
|
|||||||
+5
-3
@@ -46,8 +46,10 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
listOf(
|
listOf(
|
||||||
it.productionLinkTask,
|
it.productionLinkTask,
|
||||||
it.developmentLinkTask
|
it.developmentLinkTask
|
||||||
).forEach { task ->
|
).forEach { taskProvider ->
|
||||||
task.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
taskProvider.configure {
|
||||||
|
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +120,7 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||||
testJs.description = testTaskDescription
|
testJs.description = testTaskDescription
|
||||||
|
|
||||||
testJs.inputFileProperty.set(compilation.developmentLinkTask.outputFileProperty)
|
testJs.inputFileProperty.set(compilation.developmentLinkTask.flatMap { it.outputFileProperty })
|
||||||
|
|
||||||
testJs.dependsOn(nodeJs.npmInstallTask, nodeJs.nodeJsSetupTask)
|
testJs.dependsOn(nodeJs.npmInstallTask, nodeJs.nodeJsSetupTask)
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -71,9 +71,13 @@ open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
it.productionLinkTask.configure()
|
it.productionLinkTask.configure {
|
||||||
|
it.configure()
|
||||||
|
}
|
||||||
|
|
||||||
it.developmentLinkTask.configure()
|
it.developmentLinkTask.configure {
|
||||||
|
it.configure()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
compilation: KotlinJsIrCompilation
|
compilation: KotlinJsIrCompilation
|
||||||
) {
|
) {
|
||||||
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) {
|
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) {
|
||||||
inputFileProperty.set(compilation.developmentLinkTask.outputFileProperty)
|
inputFileProperty.set(compilation.developmentLinkTask.flatMap { it.outputFileProperty })
|
||||||
}
|
}
|
||||||
target.runTask.dependsOn(runTaskHolder)
|
target.runTask.dependsOn(runTaskHolder)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user