[Gradle, JS] Add diagnostic messages for js targets
This commit is contained in:
+2
-1
@@ -98,7 +98,8 @@ open class KotlinJsProjectExtension :
|
|||||||
// target is public property
|
// target is public property
|
||||||
// Users can write kotlin.target and it should work
|
// Users can write kotlin.target and it should work
|
||||||
// So call of target should init default canfiguration
|
// So call of target should init default canfiguration
|
||||||
private var _target: KotlinJsTargetDsl? = null
|
internal var _target: KotlinJsTargetDsl? = null
|
||||||
|
private set
|
||||||
|
|
||||||
override var target: KotlinJsTargetDsl
|
override var target: KotlinJsTargetDsl
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
+17
@@ -39,6 +39,23 @@ open class KotlinJsPlugin(
|
|||||||
defaultJsCompilerType = PropertiesProvider(project).jsCompiler
|
defaultJsCompilerType = PropertiesProvider(project).jsCompiler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project.afterEvaluate {
|
||||||
|
checkNotNull(kotlinExtension._target) {
|
||||||
|
"""
|
||||||
|
Need to initialize js target.
|
||||||
|
Use
|
||||||
|
kotlin {
|
||||||
|
js {
|
||||||
|
// Choose sub target (or both), for which js is necessary
|
||||||
|
// Affect in which tests are executed and final dist (in browser is only one bundle file)
|
||||||
|
browser()
|
||||||
|
nodejs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Explicitly create configurations for main and test
|
// Explicitly create configurations for main and test
|
||||||
// It is because in single platform we want to declare dependencies with methods not with strings in Kotlin DSL
|
// It is because in single platform we want to declare dependencies with methods not with strings in Kotlin DSL
|
||||||
// implementation("foo") instead of "implementation"("foo")
|
// implementation("foo") instead of "implementation"("foo")
|
||||||
|
|||||||
+4
-2
@@ -107,7 +107,8 @@ constructor(
|
|||||||
|
|
||||||
override val browser by browserLazyDelegate
|
override val browser by browserLazyDelegate
|
||||||
|
|
||||||
override val isBrowserConfigured: Boolean = browserLazyDelegate.isInitialized()
|
override val isBrowserConfigured: Boolean
|
||||||
|
get() = browserLazyDelegate.isInitialized()
|
||||||
|
|
||||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||||
body(browser)
|
body(browser)
|
||||||
@@ -129,7 +130,8 @@ constructor(
|
|||||||
|
|
||||||
override val nodejs by nodejsLazyDelegate
|
override val nodejs by nodejsLazyDelegate
|
||||||
|
|
||||||
override val isNodejsConfigured: Boolean = nodejsLazyDelegate.isInitialized()
|
override val isNodejsConfigured: Boolean
|
||||||
|
get() = nodejsLazyDelegate.isInitialized()
|
||||||
|
|
||||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||||
body(nodejs)
|
body(nodejs)
|
||||||
|
|||||||
+20
@@ -12,6 +12,7 @@ import org.gradle.api.Project
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.removeJsCompilerSuffix
|
import org.jetbrains.kotlin.gradle.plugin.removeJsCompilerSuffix
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset
|
||||||
@@ -39,6 +40,25 @@ open class KotlinJsTargetPreset(
|
|||||||
this.irTarget = irPreset?.createTarget(
|
this.irTarget = irPreset?.createTarget(
|
||||||
lowerCamelCaseName(name.removeJsCompilerSuffix(KotlinJsCompilerType.legacy), KotlinJsCompilerType.ir.name)
|
lowerCamelCaseName(name.removeJsCompilerSuffix(KotlinJsCompilerType.legacy), KotlinJsCompilerType.ir.name)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
project.whenEvaluated {
|
||||||
|
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||||
|
project.logger.warn(
|
||||||
|
"""
|
||||||
|
Choose sub target (or both), for which js is necessary
|
||||||
|
In next releases it will be error
|
||||||
|
Use
|
||||||
|
kotlin {
|
||||||
|
js {
|
||||||
|
// Affect in which tests are executed and final dist (in browser is only one bundle file)
|
||||||
|
browser()
|
||||||
|
nodejs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -61,7 +61,8 @@ constructor(
|
|||||||
|
|
||||||
override val browser by browserLazyDelegate
|
override val browser by browserLazyDelegate
|
||||||
|
|
||||||
override val isBrowserConfigured: Boolean = browserLazyDelegate.isInitialized()
|
override val isBrowserConfigured: Boolean
|
||||||
|
get() = browserLazyDelegate.isInitialized()
|
||||||
|
|
||||||
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
override fun browser(body: KotlinJsBrowserDsl.() -> Unit) {
|
||||||
body(browser)
|
body(browser)
|
||||||
@@ -82,7 +83,8 @@ constructor(
|
|||||||
|
|
||||||
override val nodejs by nodejsLazyDelegate
|
override val nodejs by nodejsLazyDelegate
|
||||||
|
|
||||||
override val isNodejsConfigured: Boolean = nodejsLazyDelegate.isInitialized()
|
override val isNodejsConfigured: Boolean
|
||||||
|
get() = nodejsLazyDelegate.isInitialized()
|
||||||
|
|
||||||
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) {
|
||||||
body(nodejs)
|
body(nodejs)
|
||||||
|
|||||||
+23
-5
@@ -6,13 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset
|
||||||
import org.jetbrains.kotlin.gradle.plugin.removeJsCompilerSuffix
|
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
|
||||||
open class KotlinJsIrTargetPreset(
|
open class KotlinJsIrTargetPreset(
|
||||||
@@ -28,7 +25,28 @@ open class KotlinJsIrTargetPreset(
|
|||||||
get() = KotlinPlatformType.js
|
get() = KotlinPlatformType.js
|
||||||
|
|
||||||
override fun instantiateTarget(name: String): KotlinJsIrTarget {
|
override fun instantiateTarget(name: String): KotlinJsIrTarget {
|
||||||
return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType, mixedMode)
|
return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType, mixedMode).apply {
|
||||||
|
if (!mixedMode) {
|
||||||
|
project.whenEvaluated {
|
||||||
|
if (!isBrowserConfigured && !isNodejsConfigured) {
|
||||||
|
project.logger.warn(
|
||||||
|
"""
|
||||||
|
Choose sub target (or both), for which js is necessary
|
||||||
|
In next releases it will be error
|
||||||
|
Use
|
||||||
|
kotlin {
|
||||||
|
js {
|
||||||
|
// Affect in which tests are executed and final dist (in browser is only one bundle file)
|
||||||
|
browser()
|
||||||
|
nodejs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createKotlinTargetConfigurator(): KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget> =
|
override fun createKotlinTargetConfigurator(): KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget> =
|
||||||
|
|||||||
Reference in New Issue
Block a user