From 79984b6e04be3e41217a02dad97cc0ef9efe424a Mon Sep 17 00:00:00 2001 From: Ilya Goncharov Date: Wed, 20 May 2020 14:13:15 +0300 Subject: [PATCH] [Gradle, JS] Add test on hmpp with both js #KT-38592 fixed --- .../kotlin/gradle/HierarchicalMppIT.kt | 43 ++++++++++++++++--- .../my-lib-foo/build.gradle.kts | 38 ++++++++++++++++ .../my-lib-foo/gradle.properties | 3 ++ .../my-lib-foo/settings.gradle.kts | 10 +++++ .../src/jsMain/kotlin/FooJvmAndJs.kt | 13 ++++++ .../third-party-lib/build.gradle.kts | 40 +++++++++++++++++ .../third-party-lib/settings.gradle.kts | 10 +++++ .../src/main/kotlin/ThirdPartyJs.kt | 8 ++++ 8 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/gradle.properties create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/settings.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/src/jsMain/kotlin/FooJvmAndJs.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/settings.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/src/main/kotlin/ThirdPartyJs.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt index e7dcc2709dd..fe641bc7ee8 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/HierarchicalMppIT.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 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. */ @@ -7,9 +7,10 @@ package org.jetbrains.kotlin.gradle import org.jetbrains.kotlin.gradle.internals.MULTIPLATFORM_PROJECT_METADATA_FILE_NAME import org.jetbrains.kotlin.gradle.internals.parseKotlinSourceSetMetadataFromXml +import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinProjectStructureMetadata -import org.jetbrains.kotlin.gradle.plugin.mpp.SourceSetMetadataLayout import org.jetbrains.kotlin.gradle.plugin.mpp.ModuleDependencyIdentifier +import org.jetbrains.kotlin.gradle.plugin.mpp.SourceSetMetadataLayout import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet import org.jetbrains.kotlin.gradle.util.checkedReplace import org.jetbrains.kotlin.gradle.util.modify @@ -144,8 +145,37 @@ class HierarchicalMppIT : BaseGradleIT() { } } - private fun publishThirdPartyLib(withGranularMetadata: Boolean): Project = - Project("third-party-lib", gradleVersion, "hierarchical-mpp-published-modules").apply { + @Test + fun testHmppWithJsBothDependency() { + val directoryPrefix = "hierarchical-mpp-with-js-modules" + publishThirdPartyLib( + projectName = "third-party-lib", + directoryPrefix = directoryPrefix, + withGranularMetadata = true, + jsCompilerType = KotlinJsCompilerType.BOTH + ) + + with(Project("my-lib-foo", gradleVersion, directoryPrefix)) { + setupWorkingDir() + gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl) + + build( + "publish", + "assemble", + options = defaultBuildOptions().copy(jsCompilerType = KotlinJsCompilerType.IR) + ) { + assertSuccessful() + } + } + } + + private fun publishThirdPartyLib( + projectName: String = "third-party-lib", + directoryPrefix: String = "hierarchical-mpp-published-modules", + withGranularMetadata: Boolean, + jsCompilerType: KotlinJsCompilerType = KotlinJsCompilerType.LEGACY + ): Project = + Project(projectName, gradleVersion, directoryPrefix).apply { setupWorkingDir() gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl) @@ -153,7 +183,10 @@ class HierarchicalMppIT : BaseGradleIT() { projectDir.resolve("gradle.properties").appendText("kotlin.mpp.enableGranularSourceSetsMetadata=true") } - build("publish") { + build( + "publish", + options = defaultBuildOptions().copy(jsCompilerType = jsCompilerType) + ) { assertSuccessful() } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/build.gradle.kts new file mode 100644 index 00000000000..cd3e600e082 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/build.gradle.kts @@ -0,0 +1,38 @@ +plugins { + kotlin("multiplatform").version("") + `maven-publish` +} + +repositories { + mavenLocal() + maven("../repo") + jcenter() +} + +group = "com.example.foo" +version = "1.0" + +kotlin { + js() + + sourceSets { + js().compilations["main"].defaultSourceSet { + dependencies { + api("com.example.thirdparty:third-party-lib:1.0") + implementation(kotlin("stdlib-js")) + } + } + + js().compilations["test"].defaultSourceSet { + dependencies { + implementation(kotlin("test-js")) + } + } + } +} + +publishing { + repositories { + maven("../repo") + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/gradle.properties b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/gradle.properties new file mode 100644 index 00000000000..2a559ef78a9 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/gradle.properties @@ -0,0 +1,3 @@ +kotlin.mpp.enableGranularSourceSetsMetadata=true +kotlin.native.disableCompilerDaemon=true +kotlin.mpp.enableCompatibilityMetadataVariant=true \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/settings.gradle.kts new file mode 100644 index 00000000000..e0ae6817795 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/settings.gradle.kts @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } +} + +rootProject.name = "my-lib-foo" + +enableFeaturePreview("GRADLE_METADATA") \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/src/jsMain/kotlin/FooJvmAndJs.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/src/jsMain/kotlin/FooJvmAndJs.kt new file mode 100644 index 00000000000..34f34f62010 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/my-lib-foo/src/jsMain/kotlin/FooJvmAndJs.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2020 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.foo + +import com.example.thirdparty.thirdPartyJsFun + +fun fooJvmAndJs(): String { + thirdPartyJsFun() + return "hello" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/build.gradle.kts new file mode 100644 index 00000000000..b175bdd58e2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/build.gradle.kts @@ -0,0 +1,40 @@ +plugins { + kotlin("js").version("") + `maven-publish` +} + +repositories { + mavenLocal() + jcenter() +} + +group = "com.example.thirdparty" +version = "1.0" + +kotlin { + js() + + sourceSets { + js().compilations["main"].defaultSourceSet { + dependencies { + implementation(kotlin("stdlib-js")) + } + } + js().compilations["test"].defaultSourceSet { + dependencies { + implementation(kotlin("test-js")) + } + } + } +} + +publishing { + repositories { + maven("../repo") + } + publications { + create("maven") { + from(components["kotlin"]) + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/settings.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/settings.gradle.kts new file mode 100644 index 00000000000..055148414fb --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/settings.gradle.kts @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + mavenLocal() + gradlePluginPortal() + } +} + +rootProject.name = "third-party-lib" + +enableFeaturePreview("GRADLE_METADATA") \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/src/main/kotlin/ThirdPartyJs.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/src/main/kotlin/ThirdPartyJs.kt new file mode 100644 index 00000000000..03bd3fb3a06 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/hierarchical-mpp-with-js-modules/third-party-lib/src/main/kotlin/ThirdPartyJs.kt @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2020 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.thirdparty + +fun thirdPartyJsFun() {} \ No newline at end of file