[Gradle, JS] Support custom attributes for public package json configuration
^KT-57985 fixed ^KT-57817 fixed
This commit is contained in:
committed by
Space Team
parent
af9252aa96
commit
bf757d3163
+13
@@ -485,6 +485,19 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DisplayName("Multiple targets works without clash")
|
||||||
|
@GradleTest
|
||||||
|
fun testMultipleJsTargets(gradleVersion: GradleVersion) {
|
||||||
|
project("kotlin-js-multiple-targets", gradleVersion) {
|
||||||
|
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
||||||
|
|
||||||
|
build("assemble") {
|
||||||
|
assertTasksExecuted(":compileProductionExecutableKotlinServerSide")
|
||||||
|
assertTasksExecuted(":compileProductionExecutableKotlinClientSide")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsGradlePluginTests
|
@JsGradlePluginTests
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
js("clientSide") {
|
||||||
|
attributes {
|
||||||
|
attribute(Attribute.of("js.target", String::class.java), "clientSide")
|
||||||
|
}
|
||||||
|
browser {
|
||||||
|
|
||||||
|
}
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
|
||||||
|
js("serverSide") {
|
||||||
|
attributes {
|
||||||
|
attribute(Attribute.of("js.target", String::class.java), "serverSide")
|
||||||
|
}
|
||||||
|
nodejs {
|
||||||
|
|
||||||
|
}
|
||||||
|
binaries.executable()
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
println("Sheldon")
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.example
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
println("Leonard")
|
||||||
|
}
|
||||||
+14
@@ -9,6 +9,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||||
|
|
||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
|
import org.gradle.api.attributes.AttributeContainer
|
||||||
import org.gradle.api.tasks.TaskProvider
|
import org.gradle.api.tasks.TaskProvider
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||||
@@ -53,6 +54,19 @@ open class KotlinJsCompilation @Inject internal constructor(
|
|||||||
override val processResourcesTaskName: String
|
override val processResourcesTaskName: String
|
||||||
get() = disambiguateName("processResources")
|
get() = disambiguateName("processResources")
|
||||||
|
|
||||||
|
val npmConfigurationName
|
||||||
|
get() = compilation.disambiguateName("npm")
|
||||||
|
|
||||||
|
val publicPackageJsonConfigurationName
|
||||||
|
get() = compilation.disambiguateName("publicPackageJsonConfiguration")
|
||||||
|
|
||||||
|
override val relatedConfigurationNames: List<String>
|
||||||
|
get() = super.relatedConfigurationNames + npmConfigurationName + publicPackageJsonConfigurationName
|
||||||
|
|
||||||
|
override fun getAttributes(): AttributeContainer {
|
||||||
|
return compilation.attributes
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@Deprecated("Accessing task instance directly is deprecated", replaceWith = ReplaceWith("compileTaskProvider"))
|
@Deprecated("Accessing task instance directly is deprecated", replaceWith = ReplaceWith("compileTaskProvider"))
|
||||||
override val compileKotlinTask: Kotlin2JsCompile
|
override val compileKotlinTask: Kotlin2JsCompile
|
||||||
|
|||||||
+1
-1
@@ -132,4 +132,4 @@ internal val JsBinary.executeTaskBaseName: String
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|
||||||
internal val COMPILE_SYNC = "compileSync"
|
internal const val COMPILE_SYNC = "compileSync"
|
||||||
+3
-3
@@ -103,7 +103,7 @@ class KotlinCompilationNpmResolver(
|
|||||||
|
|
||||||
override fun toString(): String = "KotlinCompilationNpmResolver(${npmProject.name})"
|
override fun toString(): String = "KotlinCompilationNpmResolver(${npmProject.name})"
|
||||||
|
|
||||||
val aggregatedConfiguration: Configuration by lazy {
|
val aggregatedConfiguration: Configuration = run {
|
||||||
createAggregatedConfiguration()
|
createAggregatedConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ class KotlinCompilationNpmResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createAggregatedConfiguration(): Configuration {
|
private fun createAggregatedConfiguration(): Configuration {
|
||||||
val all = project.configurations.create(compilation.disambiguateName("npm"))
|
val all = project.configurations.create(compilation.npmConfigurationName)
|
||||||
|
|
||||||
all.usesPlatformOf(target)
|
all.usesPlatformOf(target)
|
||||||
all.attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.consumerRuntimeUsage(target))
|
all.attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.consumerRuntimeUsage(target))
|
||||||
@@ -156,7 +156,7 @@ class KotlinCompilationNpmResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createPublicPackageJsonConfiguration(): Configuration {
|
private fun createPublicPackageJsonConfiguration(): Configuration {
|
||||||
val all = project.configurations.create(compilation.disambiguateName("publicPackageJsonConfiguration"))
|
val all = project.configurations.create(compilation.publicPackageJsonConfigurationName)
|
||||||
|
|
||||||
all.usesPlatformOf(target)
|
all.usesPlatformOf(target)
|
||||||
all.attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.consumerRuntimeUsage(target))
|
all.attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.consumerRuntimeUsage(target))
|
||||||
|
|||||||
Reference in New Issue
Block a user