[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)) {
|
||||||
|
|||||||
+102
-102
@@ -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,59 +82,66 @@ 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
|
|
||||||
val runTask = project.registerTask<KotlinWebpack>(
|
|
||||||
disambiguateCamelCased(
|
|
||||||
buildVariant.name,
|
|
||||||
RUN_TASK_NAME
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
it.dependsOn(
|
|
||||||
nodeJs.npmInstallTask,
|
|
||||||
target.project.tasks.named(compilation.processResourcesTaskName)
|
|
||||||
)
|
|
||||||
|
|
||||||
it.configureOptimization(kind)
|
compilation.binaries
|
||||||
|
.matching { it is Executable }
|
||||||
|
.all { binary ->
|
||||||
|
binary as Executable
|
||||||
|
|
||||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
val type = binary.type
|
||||||
it.compilation = compilation
|
|
||||||
it.description = "start ${kind.name.toLowerCase()} webpack dev server"
|
|
||||||
|
|
||||||
it.devServer = KotlinWebpackConfig.DevServer(
|
val runTask = project.registerTask<KotlinWebpack>(
|
||||||
open = true,
|
disambiguateCamelCased(
|
||||||
contentBase = listOf(compilation.output.resourcesDir.canonicalPath)
|
binary.executeTaskBaseName,
|
||||||
)
|
RUN_TASK_NAME
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
it.dependsOn(
|
||||||
|
nodeJs.npmInstallTask,
|
||||||
|
target.project.tasks.named(compilation.processResourcesTaskName)
|
||||||
|
)
|
||||||
|
|
||||||
it.outputs.upToDateWhen { false }
|
it.configureOptimization(type)
|
||||||
|
|
||||||
when (kind) {
|
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||||
BuildVariantKind.PRODUCTION -> {
|
it.compilation = compilation
|
||||||
// Breaking of Task Configuration Avoidance is not so critical
|
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||||
// because this task is dependent on DCE task
|
|
||||||
it.entry = dceTaskProvider.get()
|
it.devServer = KotlinWebpackConfig.DevServer(
|
||||||
.destinationDir
|
open = true,
|
||||||
.resolve(compileKotlinTask.outputFile.name)
|
contentBase = listOf(compilation.output.resourcesDir.canonicalPath)
|
||||||
it.resolveFromModulesFirst = true
|
)
|
||||||
it.dependsOn(dceTaskProvider)
|
|
||||||
|
it.outputs.upToDateWhen { false }
|
||||||
|
|
||||||
|
when (type) {
|
||||||
|
BuildVariantKind.PRODUCTION -> {
|
||||||
|
// Breaking of Task Configuration Avoidance is not so critical
|
||||||
|
// because this task is dependent on DCE task
|
||||||
|
it.entry = dceTaskProvider.get()
|
||||||
|
.destinationDir
|
||||||
|
.resolve(compileKotlinTask.outputFile.name)
|
||||||
|
it.resolveFromModulesFirst = true
|
||||||
|
it.dependsOn(dceTaskProvider)
|
||||||
|
}
|
||||||
|
BuildVariantKind.DEVELOPMENT -> {
|
||||||
|
it.dependsOn(compileKotlinTask)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
BuildVariantKind.DEVELOPMENT -> {
|
|
||||||
it.dependsOn(compileKotlinTask)
|
commonRunConfigurations.forEach { configure ->
|
||||||
|
it.configure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commonRunConfigurations.forEach { configure ->
|
if (type == BuildVariantKind.DEVELOPMENT) {
|
||||||
it.configure()
|
target.runTask.dependsOn(runTask)
|
||||||
|
commonRunTask.configure {
|
||||||
|
it.dependsOn(runTask)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind == BuildVariantKind.DEVELOPMENT) {
|
|
||||||
target.runTask.dependsOn(runTask)
|
|
||||||
project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {
|
|
||||||
it.dependsOn(runTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureBuild(
|
private fun configureBuild(
|
||||||
@@ -167,60 +172,65 @@ 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 }
|
||||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
.all { binary ->
|
||||||
disambiguateCamelCased(
|
binary as Executable
|
||||||
buildVariant.name,
|
|
||||||
WEBPACK_TASK_NAME
|
|
||||||
|
|
||||||
)
|
val type = binary.type
|
||||||
) {
|
|
||||||
it.dependsOn(
|
|
||||||
nodeJs.npmInstallTask,
|
|
||||||
processResourcesTask,
|
|
||||||
distributeResourcesTask
|
|
||||||
)
|
|
||||||
|
|
||||||
it.configureOptimization(kind)
|
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||||
|
disambiguateCamelCased(
|
||||||
|
binary.executeTaskBaseName,
|
||||||
|
WEBPACK_TASK_NAME
|
||||||
|
|
||||||
it.compilation = compilation
|
)
|
||||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
|
||||||
it.destinationDirectory = distribution.directory!!
|
|
||||||
|
|
||||||
when (kind) {
|
|
||||||
BuildVariantKind.PRODUCTION -> {
|
|
||||||
// Breaking of Task Configuration Avoidance is not so critical
|
|
||||||
// because this task is dependent on DCE task
|
|
||||||
it.entry = dceTaskProvider.get()
|
|
||||||
.destinationDir
|
|
||||||
.resolve(compileKotlinTask.outputFile.name)
|
|
||||||
it.resolveFromModulesFirst = true
|
|
||||||
it.dependsOn(dceTaskProvider)
|
|
||||||
}
|
|
||||||
BuildVariantKind.DEVELOPMENT -> {
|
|
||||||
it.dependsOn(compileKotlinTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
commonWebpackConfigurations.forEach { configure ->
|
|
||||||
it.configure()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind == BuildVariantKind.PRODUCTION) {
|
|
||||||
assembleTask.dependsOn(webpackTask)
|
|
||||||
val webpackCommonTask = project.registerTask<Task>(
|
|
||||||
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
|
||||||
) {
|
) {
|
||||||
it.dependsOn(webpackTask)
|
it.dependsOn(
|
||||||
|
nodeJs.npmInstallTask,
|
||||||
|
processResourcesTask,
|
||||||
|
distributeResourcesTask
|
||||||
|
)
|
||||||
|
|
||||||
|
it.configureOptimization(type)
|
||||||
|
|
||||||
|
it.compilation = compilation
|
||||||
|
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||||
|
it.destinationDirectory = distribution.directory
|
||||||
|
|
||||||
|
when (type) {
|
||||||
|
BuildVariantKind.PRODUCTION -> {
|
||||||
|
// Breaking of Task Configuration Avoidance is not so critical
|
||||||
|
// because this task is dependent on DCE task
|
||||||
|
it.entry = dceTaskProvider.get()
|
||||||
|
.destinationDir
|
||||||
|
.resolve(compileKotlinTask.outputFile.name)
|
||||||
|
it.resolveFromModulesFirst = true
|
||||||
|
it.dependsOn(dceTaskProvider)
|
||||||
|
}
|
||||||
|
BuildVariantKind.DEVELOPMENT -> {
|
||||||
|
it.dependsOn(compileKotlinTask)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commonWebpackConfigurations.forEach { configure ->
|
||||||
|
it.configure()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
|
||||||
it.dependsOn(webpackCommonTask)
|
if (type == BuildVariantKind.PRODUCTION) {
|
||||||
it.dependsOn(distributeResourcesTask)
|
assembleTask.dependsOn(webpackTask)
|
||||||
|
val webpackCommonTask = project.registerTask<Task>(
|
||||||
|
disambiguateCamelCased(WEBPACK_TASK_NAME)
|
||||||
|
) {
|
||||||
|
it.dependsOn(webpackTask)
|
||||||
|
}
|
||||||
|
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||||
|
it.dependsOn(webpackCommonTask)
|
||||||
|
it.dependsOn(distributeResourcesTask)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureDce(compilation: KotlinJsCompilation): TaskProvider<KotlinJsDceTask> {
|
private fun configureDce(compilation: KotlinJsCompilation): TaskProvider<KotlinJsDceTask> {
|
||||||
@@ -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