[Gradle, JS] Migrate from build variants on binaries
This commit is contained in:
+3
-1
@@ -168,7 +168,9 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
|
|
||||||
if (type == BuildVariantKind.PRODUCTION) {
|
if (type == BuildVariantKind.PRODUCTION) {
|
||||||
assembleTask.dependsOn(webpackTask)
|
assembleTask.dependsOn(webpackTask)
|
||||||
val webpackCommonTask = project.registerTask<Task>(disambiguateCamelCased(WEBPACK_TASK_NAME)) {
|
val webpackCommonTask = project.registerTask<Task>(
|
||||||
|
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
||||||
|
) {
|
||||||
it.dependsOn(webpackTask)
|
it.dependsOn(webpackTask)
|
||||||
}
|
}
|
||||||
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||||
|
|||||||
+29
-29
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
||||||
|
|
||||||
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.tasks.Copy
|
import org.gradle.api.tasks.Copy
|
||||||
@@ -16,6 +15,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.ir.Executable
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||||
@@ -38,8 +38,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf()
|
private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf()
|
||||||
private val distribution: Distribution = BrowserDistribution()
|
private val distribution: Distribution = BrowserDistribution()
|
||||||
|
|
||||||
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
|
||||||
|
|
||||||
override val testTaskDescription: String
|
override val testTaskDescription: String
|
||||||
get() = "Run all ${target.name} tests inside browser using karma and webpack"
|
get() = "Run all ${target.name} tests inside browser using karma and webpack"
|
||||||
|
|
||||||
@@ -84,11 +82,18 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
val compileKotlinTask = compilation.compileKotlinTask
|
val compileKotlinTask = compilation.compileKotlinTask
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
val commonRunTask = project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {}
|
||||||
val kind = buildVariant.kind
|
|
||||||
|
compilation.binaries
|
||||||
|
.matching { it is Executable }
|
||||||
|
.all { binary ->
|
||||||
|
binary as Executable
|
||||||
|
|
||||||
|
val type = binary.type
|
||||||
|
|
||||||
val runTask = project.registerTask<KotlinWebpack>(
|
val runTask = project.registerTask<KotlinWebpack>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
buildVariant.name,
|
binary.executeTaskBaseName,
|
||||||
RUN_TASK_NAME
|
RUN_TASK_NAME
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
@@ -97,11 +102,11 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
target.project.tasks.named(compilation.processResourcesTaskName)
|
target.project.tasks.named(compilation.processResourcesTaskName)
|
||||||
)
|
)
|
||||||
|
|
||||||
it.configureOptimization(kind)
|
it.configureOptimization(type)
|
||||||
|
|
||||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.description = "start ${kind.name.toLowerCase()} webpack dev server"
|
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||||
|
|
||||||
it.devServer = KotlinWebpackConfig.DevServer(
|
it.devServer = KotlinWebpackConfig.DevServer(
|
||||||
open = true,
|
open = true,
|
||||||
@@ -110,7 +115,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
it.outputs.upToDateWhen { false }
|
it.outputs.upToDateWhen { false }
|
||||||
|
|
||||||
when (kind) {
|
when (type) {
|
||||||
BuildVariantKind.PRODUCTION -> {
|
BuildVariantKind.PRODUCTION -> {
|
||||||
// Breaking of Task Configuration Avoidance is not so critical
|
// Breaking of Task Configuration Avoidance is not so critical
|
||||||
// because this task is dependent on DCE task
|
// because this task is dependent on DCE task
|
||||||
@@ -130,9 +135,9 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind == BuildVariantKind.DEVELOPMENT) {
|
if (type == BuildVariantKind.DEVELOPMENT) {
|
||||||
target.runTask.dependsOn(runTask)
|
target.runTask.dependsOn(runTask)
|
||||||
project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {
|
commonRunTask.configure {
|
||||||
it.dependsOn(runTask)
|
it.dependsOn(runTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,11 +172,16 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||||
assembleTask.dependsOn(distributeResourcesTask)
|
assembleTask.dependsOn(distributeResourcesTask)
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
compilation.binaries
|
||||||
val kind = buildVariant.kind
|
.matching { it is Executable }
|
||||||
|
.all { binary ->
|
||||||
|
binary as Executable
|
||||||
|
|
||||||
|
val type = binary.type
|
||||||
|
|
||||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
buildVariant.name,
|
binary.executeTaskBaseName,
|
||||||
WEBPACK_TASK_NAME
|
WEBPACK_TASK_NAME
|
||||||
|
|
||||||
)
|
)
|
||||||
@@ -182,13 +192,13 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
distributeResourcesTask
|
distributeResourcesTask
|
||||||
)
|
)
|
||||||
|
|
||||||
it.configureOptimization(kind)
|
it.configureOptimization(type)
|
||||||
|
|
||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||||
it.destinationDirectory = distribution.directory!!
|
it.destinationDirectory = distribution.directory
|
||||||
|
|
||||||
when (kind) {
|
when (type) {
|
||||||
BuildVariantKind.PRODUCTION -> {
|
BuildVariantKind.PRODUCTION -> {
|
||||||
// Breaking of Task Configuration Avoidance is not so critical
|
// Breaking of Task Configuration Avoidance is not so critical
|
||||||
// because this task is dependent on DCE task
|
// because this task is dependent on DCE task
|
||||||
@@ -208,7 +218,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind == BuildVariantKind.PRODUCTION) {
|
if (type == BuildVariantKind.PRODUCTION) {
|
||||||
assembleTask.dependsOn(webpackTask)
|
assembleTask.dependsOn(webpackTask)
|
||||||
val webpackCommonTask = project.registerTask<Task>(
|
val webpackCommonTask = project.registerTask<Task>(
|
||||||
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
||||||
@@ -275,16 +285,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
BuildVariantKind.DEVELOPMENT -> debugValue
|
BuildVariantKind.DEVELOPMENT -> debugValue
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configureBuildVariants() {
|
|
||||||
buildVariants = project.container(BuildVariant::class.java)
|
|
||||||
buildVariants.create(PRODUCTION) {
|
|
||||||
it.kind = BuildVariantKind.PRODUCTION
|
|
||||||
}
|
|
||||||
buildVariants.create(DEVELOPMENT) {
|
|
||||||
it.kind = BuildVariantKind.DEVELOPMENT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val DCE_TASK_PREFIX = "processDce"
|
const val DCE_TASK_PREFIX = "processDce"
|
||||||
const val DCE_TASK_SUFFIX = "kotlinJs"
|
const val DCE_TASK_SUFFIX = "kotlinJs"
|
||||||
|
|||||||
-3
@@ -39,7 +39,6 @@ abstract class KotlinJsSubTarget(
|
|||||||
private set
|
private set
|
||||||
|
|
||||||
internal open fun produceExecutable() {
|
internal open fun produceExecutable() {
|
||||||
configureBuildVariants()
|
|
||||||
configureMain()
|
configureMain()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,8 +60,6 @@ abstract class KotlinJsSubTarget(
|
|||||||
protected fun disambiguateCamelCased(vararg names: String): String =
|
protected fun disambiguateCamelCased(vararg names: String): String =
|
||||||
lowerCamelCaseName(target.disambiguationClassifier, disambiguationClassifier, *names)
|
lowerCamelCaseName(target.disambiguationClassifier, disambiguationClassifier, *names)
|
||||||
|
|
||||||
abstract fun configureBuildVariants()
|
|
||||||
|
|
||||||
private fun configureTests() {
|
private fun configureTests() {
|
||||||
testRuns = project.container(KotlinJsPlatformTestRun::class.java) { name -> KotlinJsPlatformTestRun(name, target) }.also {
|
testRuns = project.container(KotlinJsPlatformTestRun::class.java) { name -> KotlinJsPlatformTestRun(name, target) }.also {
|
||||||
(this as ExtensionAware).extensions.add(this::testRuns.name, it)
|
(this as ExtensionAware).extensions.add(this::testRuns.name, it)
|
||||||
|
|||||||
-3
@@ -44,7 +44,4 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
}
|
}
|
||||||
target.runTask.dependsOn(runTaskHolder)
|
target.runTask.dependsOn(runTaskHolder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configureBuildVariants() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user