Gradle, js: use js compilation only after target configuration
This commit is contained in:
+7
-2
@@ -14,17 +14,22 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolveTask
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinBrowserJs
|
||||
import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinNodeJs
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
class KotlinJsTarget(project: Project, platformType: KotlinPlatformType) :
|
||||
KotlinOnlyTarget<KotlinJsCompilation>(project, platformType), KotlinJsTargetDsl {
|
||||
val npmResolveTaskHolder = project.locateOrRegisterTask<NpmResolveTask>("npmResolve") {}
|
||||
val npmResolveTask
|
||||
get() = npmResolveTaskHolder.getTaskOrProvider()
|
||||
|
||||
val testTaskName = lowerCamelCaseName(disambiguationClassifier, testTaskNameSuffix)
|
||||
val testTaskName get() = lowerCamelCaseName(disambiguationClassifier, testTaskNameSuffix)
|
||||
val testTask get() = project.tasks.maybeCreate(testTaskName)
|
||||
|
||||
val runTaskName = lowerCamelCaseName(disambiguationClassifier, runTaskNameSuffix)
|
||||
val runTaskName get() = lowerCamelCaseName(disambiguationClassifier, runTaskNameSuffix)
|
||||
val runTask get() = project.tasks.maybeCreate(runTaskName)
|
||||
|
||||
private var hasSubtargets = false
|
||||
|
||||
+15
-6
@@ -27,19 +27,28 @@ open class KotlinJsTargetConfigurator(kotlinPluginVersion: String) :
|
||||
target.configureDefaults()
|
||||
super.configureTarget(target)
|
||||
|
||||
target.project.tasks.maybeCreate(runTaskNameSuffix).dependsOn(target.runTask)
|
||||
target.compilations.forEach {
|
||||
it.compileKotlinTask.dependsOn(target.npmResolveTask)
|
||||
}
|
||||
|
||||
if (target.disambiguationClassifier != null) {
|
||||
target.project.tasks.maybeCreate(runTaskNameSuffix).dependsOn(target.runTask)
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureTest(target: KotlinOnlyTarget<KotlinJsCompilation>) {
|
||||
// tests configured in KotlinJsSubTarget.configure
|
||||
|
||||
target as KotlinJsTarget
|
||||
val tasks = target.project.tasks
|
||||
val check = tasks.findByName(JavaBasePlugin.CHECK_TASK_NAME)
|
||||
|
||||
@Suppress("IfThenToSafeAccess")
|
||||
if (check != null) {
|
||||
check.dependsOn(target.testTask)
|
||||
if (target.disambiguationClassifier != null) {
|
||||
val tasks = target.project.tasks
|
||||
val check = tasks.findByName(JavaBasePlugin.CHECK_TASK_NAME)
|
||||
|
||||
@Suppress("IfThenToSafeAccess")
|
||||
if (check != null) {
|
||||
check.dependsOn(target.testTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -42,10 +42,10 @@ class KotlinBrowserJs(target: KotlinJsTarget) :
|
||||
override fun configureRun(compilation: KotlinJsCompilation) {
|
||||
val project = compilation.target.project
|
||||
val npmProject = project.npmProject
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
|
||||
project.createOrRegisterTask<KotlinWebpack>(disambiguateCamelCased("webpack")) {
|
||||
it.dependsOn(npmResolveTask, compileKotlinTask)
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(target.npmResolveTask, compileKotlinTask)
|
||||
|
||||
it.entry = npmProject.compileOutput(compileKotlinTask)
|
||||
|
||||
@@ -53,7 +53,8 @@ class KotlinBrowserJs(target: KotlinJsTarget) :
|
||||
}
|
||||
|
||||
project.createOrRegisterTask<KotlinWebpack>(disambiguateCamelCased("run")) {
|
||||
it.dependsOn(npmResolveTask, compileKotlinTask)
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(target.npmResolveTask, compileKotlinTask)
|
||||
|
||||
it.bin = "webpack-dev-server"
|
||||
it.entry = npmProject.compileOutput(compileKotlinTask)
|
||||
|
||||
+3
-10
@@ -8,11 +8,9 @@ package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolveTask
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.createOrRegisterTask
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.configureConventions
|
||||
@@ -25,8 +23,6 @@ abstract class KotlinJsSubTarget(
|
||||
) : KotlinJsSubTargetDsl {
|
||||
val project get() = target.project
|
||||
|
||||
val npmResolveTask = project.createOrRegisterTask<NpmResolveTask>("npmResolve") {}
|
||||
|
||||
val runTaskName = disambiguateCamelCased("run")
|
||||
val testTaskName = disambiguateCamelCased("test")
|
||||
|
||||
@@ -59,17 +55,15 @@ abstract class KotlinJsSubTarget(
|
||||
}
|
||||
|
||||
private fun configureTests(compilation: KotlinJsCompilation) {
|
||||
val compileTask = compilation.compileKotlinTask
|
||||
|
||||
compileTask.dependsOn(npmResolveTask)
|
||||
|
||||
// apply plugin (cannot be done at task instantiation time)
|
||||
val nodeJs = NodeJsPlugin.apply(target.project).root
|
||||
|
||||
val testJs = project.createOrRegisterTask<KotlinJsTest>(testTaskName) { testJs ->
|
||||
val compileTask = compilation.compileKotlinTask
|
||||
|
||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
|
||||
testJs.dependsOn(npmResolveTask, compileTask, nodeJs.nodeJsSetupTask)
|
||||
testJs.dependsOn(target.npmResolveTask, compileTask, nodeJs.nodeJsSetupTask)
|
||||
|
||||
testJs.onlyIf {
|
||||
compileTask.outputFile.exists()
|
||||
@@ -99,7 +93,6 @@ abstract class KotlinJsSubTarget(
|
||||
fun configureRun() {
|
||||
target.compilations.all { compilation ->
|
||||
if (compilation.name == KotlinCompilation.MAIN_COMPILATION_NAME) {
|
||||
compilation.compileKotlinTask.dependsOn(npmResolveTask)
|
||||
configureRun(compilation)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -33,9 +33,13 @@ class KotlinNodeJs(target: KotlinJsTarget) :
|
||||
}
|
||||
|
||||
val project = target.project
|
||||
|
||||
project.createOrRegisterTask<NodeJsExec>(disambiguateCamelCased("run")) {
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(target.npmResolveTask, compileKotlinTask)
|
||||
|
||||
val npmProject = project.npmProject
|
||||
it.args(npmProject.compileOutput(compilation.compileKotlinTask))
|
||||
it.args(npmProject.compileOutput(compileKotlinTask))
|
||||
|
||||
// source maps support
|
||||
it.args("--require", npmProject.getModuleEntryPath("kotlin-test-nodejs-runner"))
|
||||
|
||||
Reference in New Issue
Block a user