diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index fab17fbe7a59e..95cd6a63dc1d5 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -1,6 +1,7 @@ plugins { kotlin("jvm") id("jps-compatible") + id("d8-configuration") } val compilerModules: Array by rootProject.extra @@ -44,7 +45,6 @@ sourceSets { } } -useD8Plugin() projectTest( parallel = true, defineJDKEnvVariables = listOf(JdkMajorVersion.JDK_1_8, JdkMajorVersion.JDK_11_0, JdkMajorVersion.JDK_17_0) diff --git a/compiler/fir/analysis-tests/build.gradle.kts b/compiler/fir/analysis-tests/build.gradle.kts index d58e487505534..fa9b01d2037fe 100644 --- a/compiler/fir/analysis-tests/build.gradle.kts +++ b/compiler/fir/analysis-tests/build.gradle.kts @@ -8,6 +8,7 @@ import org.jetbrains.kotlin.ideaExt.idea plugins { kotlin("jvm") id("jps-compatible") + id("d8-configuration") } dependencies { @@ -62,8 +63,6 @@ if (kotlinBuildProperties.isInJpsBuildIdeaSync) { } } -useD8Plugin() - projectTest( jUnitMode = JUnitMode.JUnit5, defineJDKEnvVariables = listOf( diff --git a/compiler/incremental-compilation-impl/build.gradle.kts b/compiler/incremental-compilation-impl/build.gradle.kts index 03ba1fe7cddee..88d29b3388a40 100644 --- a/compiler/incremental-compilation-impl/build.gradle.kts +++ b/compiler/incremental-compilation-impl/build.gradle.kts @@ -1,6 +1,7 @@ plugins { kotlin("jvm") id("jps-compatible") + id("d8-configuration") } dependencies { @@ -41,8 +42,6 @@ sourceSets { "test" { projectDefault() } } -useD8Plugin() - projectTest(parallel = true) { workingDir = rootDir useJsIrBoxTests(version = version, buildDir = layout.buildDirectory) diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts index 4d315a93aa08d..6a6ac8e6e24e2 100644 --- a/js/js.tests/build.gradle.kts +++ b/js/js.tests/build.gradle.kts @@ -1,6 +1,7 @@ import com.github.gradle.node.npm.task.NpmTask import com.github.gradle.node.variant.computeNodeExec import org.apache.tools.ant.filters.FixCrLfFilter +import org.jetbrains.kotlin.build.d8.D8Extension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute @@ -12,6 +13,7 @@ plugins { kotlin("plugin.serialization") id("jps-compatible") alias(libs.plugins.gradle.node) + id("d8-configuration") } val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true @@ -88,7 +90,6 @@ dependencies { val generationRoot = projectDir.resolve("tests-gen") -useD8Plugin() optInToExperimentalCompilerApi() sourceSets { @@ -213,7 +214,9 @@ fun Test.setupNodeJs() { } fun Test.setUpJsBoxTests(tags: String?) { - setupV8() + with(project.the()) { + setupV8() + } setupNodeJs() dependsOn(npmInstall) diff --git a/js/js.tests/klib-compatibility/build.gradle.kts b/js/js.tests/klib-compatibility/build.gradle.kts index 4a3b763353a2c..fbdb789c95b88 100644 --- a/js/js.tests/klib-compatibility/build.gradle.kts +++ b/js/js.tests/klib-compatibility/build.gradle.kts @@ -1,7 +1,9 @@ +import org.jetbrains.kotlin.build.d8.D8Extension import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute plugins { kotlin("jvm") + id("d8-configuration") } dependencies { @@ -46,13 +48,14 @@ sourceSets { testsJar {} fun Test.setUpJsBoxTests() { - setupV8() + with(project.the()) { + setupV8() + } dependsOn(":dist") workingDir = rootDir } -useD8Plugin() projectTest(jUnitMode = JUnitMode.JUnit5) { dependsOn(releasedCompilerDist) systemProperty("kotlin.internal.js.test.latestReleasedCompilerLocation", releasedCompilerArtifactsTarget.get().asFile.absolutePath) diff --git a/libraries/stdlib/build.gradle.kts b/libraries/stdlib/build.gradle.kts index 1a2f75ee091b9..5632ed9105387 100644 --- a/libraries/stdlib/build.gradle.kts +++ b/libraries/stdlib/build.gradle.kts @@ -27,6 +27,7 @@ plugins { `maven-publish` signing id("nodejs-cache-redirector-configuration") + id("d8-configuration") } description = "Kotlin Standard Library" @@ -596,11 +597,6 @@ kotlin { } } -plugins.apply(D8Plugin::class.java) - -@OptIn(ExperimentalWasmDsl::class) -the().version = v8Version - dependencies { val jvmMainApi by configurations.getting val metadataApiElements by configurations.getting diff --git a/plugins/atomicfu/atomicfu-compiler/build.gradle.kts b/plugins/atomicfu/atomicfu-compiler/build.gradle.kts index ff61994b44c88..c4ed3cb6d29a2 100644 --- a/plugins/atomicfu/atomicfu-compiler/build.gradle.kts +++ b/plugins/atomicfu/atomicfu-compiler/build.gradle.kts @@ -9,6 +9,7 @@ description = "Atomicfu Compiler Plugin" plugins { kotlin("jvm") id("jps-compatible") + id("d8-configuration") } // WARNING: Native target is host-dependent. Re-running the same build on another host OS may bring to a different result. @@ -174,7 +175,6 @@ sourceSets { } testsJar() -useD8Plugin() projectTest(jUnitMode = JUnitMode.JUnit5) { useJUnitPlatform { diff --git a/plugins/js-plain-objects/compiler-plugin/build.gradle.kts b/plugins/js-plain-objects/compiler-plugin/build.gradle.kts index fa7403e3ad0ba..113116d4bc670 100644 --- a/plugins/js-plain-objects/compiler-plugin/build.gradle.kts +++ b/plugins/js-plain-objects/compiler-plugin/build.gradle.kts @@ -7,6 +7,7 @@ description = "JavaScript Plain Objects Compiler Plugin" plugins { kotlin("jvm") id("jps-compatible") + id("d8-configuration") } val jsoIrRuntimeForTests by configurations.creating { @@ -74,8 +75,6 @@ sourcesJar() javadocJar() testsJar() -useD8Plugin() - projectTest(parallel = true, jUnitMode = JUnitMode.JUnit5) { useJUnitPlatform() useJsIrBoxTests(version = version, buildDir = layout.buildDirectory) diff --git a/plugins/kotlinx-serialization/build.gradle.kts b/plugins/kotlinx-serialization/build.gradle.kts index 7ab8fcf790909..732614b91045a 100644 --- a/plugins/kotlinx-serialization/build.gradle.kts +++ b/plugins/kotlinx-serialization/build.gradle.kts @@ -6,6 +6,7 @@ description = "Kotlin Serialization Compiler Plugin" plugins { kotlin("jvm") id("jps-compatible") + id("d8-configuration") } val jsonJsIrRuntimeForTests: Configuration by configurations.creating { @@ -88,7 +89,6 @@ val runtimeJar = runtimeJar { sourcesJar() javadocJar() testsJar() -useD8Plugin() val distCompat by configurations.creating { isCanBeResolved = false diff --git a/repo/gradle-build-conventions/buildsrc-compat/build.gradle.kts b/repo/gradle-build-conventions/buildsrc-compat/build.gradle.kts index 67e19994c1101..3e7a4744cedf7 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/build.gradle.kts +++ b/repo/gradle-build-conventions/buildsrc-compat/build.gradle.kts @@ -123,6 +123,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect:${project.bootstrapKotlinVersion}") implementation(libs.gson) implementation(libs.kotlinx.metadataJvm) + implementation(project(":d8-configuration")) } tasks.register("checkBuild") { diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/repoDependencies.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/repoDependencies.kt index 694d137a48b6b..e39ccc38782c9 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/repoDependencies.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/repoDependencies.kt @@ -218,7 +218,6 @@ fun Project.kotlinxCollectionsImmutable() = val Project.kotlinNativeVersion: String get() = property("versions.kotlin-native") as String val Project.nodejsVersion: String get() = property("versions.nodejs") as String -val Project.v8Version: String get() = property("versions.v8") as String fun File.matchMaybeVersionedArtifact(baseName: String) = name.matches(baseName.toMaybeVersionedJarRegex()) diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupIrJsBoxTests.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupIrJsBoxTests.kt index e814505f1291e..be80eae3c80f1 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupIrJsBoxTests.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupIrJsBoxTests.kt @@ -5,6 +5,8 @@ import org.gradle.api.file.Directory import org.gradle.api.provider.Provider import org.gradle.api.tasks.testing.Test +import org.gradle.kotlin.dsl.the +import org.jetbrains.kotlin.build.d8.D8Extension fun Test.useJsIrBoxTests( version: Any, @@ -13,7 +15,9 @@ fun Test.useJsIrBoxTests( reducedStdlibPath: String = "libraries/stdlib/js-ir-minimal-for-test/build/classes/kotlin/js/main", domApiCompatPath: String = "libraries/kotlin-dom-api-compat/build/classes/kotlin/main" ) { - setupV8() + with(project.the()) { + setupV8() + } dependsOn(":kotlin-stdlib:jsJar") dependsOn(":kotlin-stdlib:jsJarForTests") // TODO: think how to remove dependency on the artifact in this place dependsOn(":kotlin-test:jsJar") diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupV8.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupV8.kt index f212afb4b8193..af295f4ce3c92 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupV8.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/setupV8.kt @@ -6,48 +6,9 @@ import org.gradle.api.Project import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.the -import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl -import org.jetbrains.kotlin.gradle.targets.js.d8.D8EnvSpec -import org.jetbrains.kotlin.gradle.targets.js.d8.D8Plugin -import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin -@OptIn(ExperimentalWasmDsl::class) -private object V8Utils { - lateinit var d8Plugin: D8EnvSpec - lateinit var d8Root: D8RootExtension - - fun useD8Plugin(project: Project) { - project.plugins.apply(D8Plugin::class.java) - d8Plugin = project.the() - project.rootProject.plugins.apply(D8Plugin::class.java) - d8Root = project.rootProject.the() - d8Plugin.version.set(project.v8Version) - @Suppress("DEPRECATION") - d8Root.version = project.v8Version - } -} - -fun Project.useD8Plugin() { - V8Utils.useD8Plugin(this) -} - -@OptIn(ExperimentalWasmDsl::class) -fun Test.setupV8() { - with(V8Utils.d8Plugin) { - dependsOn(project.d8SetupTaskProvider) - } - dependsOn(V8Utils.d8Root.setupTaskProvider) - val v8ExecutablePath = project.provider { - V8Utils.d8Root.requireConfigured().executablePath.absolutePath - } - doFirst { - systemProperty("javascript.engine.path.V8", v8ExecutablePath.get()) - } -} - private object NodeJsUtils { lateinit var nodeJsPlugin: NodeJsRootExtension diff --git a/repo/gradle-build-conventions/d8-configuration/build.gradle.kts b/repo/gradle-build-conventions/d8-configuration/build.gradle.kts new file mode 100644 index 0000000000000..212ffe419ea83 --- /dev/null +++ b/repo/gradle-build-conventions/d8-configuration/build.gradle.kts @@ -0,0 +1,27 @@ +plugins { + `kotlin-dsl` + id("org.jetbrains.kotlin.jvm") +} + +repositories { + maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies") + mavenCentral() + gradlePluginPortal() + + extra["bootstrapKotlinRepo"]?.let { + maven(url = it) + } +} + +kotlin { + jvmToolchain(8) + + compilerOptions { + allWarningsAsErrors.set(true) + } +} + +dependencies { + compileOnly(kotlin("stdlib", embeddedKotlinVersion)) + compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}") +} diff --git a/repo/gradle-build-conventions/d8-configuration/src/main/kotlin/d8-configuration.gradle.kts b/repo/gradle-build-conventions/d8-configuration/src/main/kotlin/d8-configuration.gradle.kts new file mode 100644 index 0000000000000..4128384f06e4a --- /dev/null +++ b/repo/gradle-build-conventions/d8-configuration/src/main/kotlin/d8-configuration.gradle.kts @@ -0,0 +1,25 @@ +@file:OptIn(ExperimentalWasmDsl::class) + +import org.jetbrains.kotlin.build.d8.D8Extension +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.targets.js.d8.D8EnvSpec +import org.jetbrains.kotlin.gradle.targets.js.d8.D8Plugin +import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension + +project.plugins.apply(D8Plugin::class.java) +val d8EnvSpec = project.the() +project.rootProject.plugins.apply(D8Plugin::class.java) +val d8Root = project.rootProject.the() + +val d8KotlinBuild = extensions.create( + "d8KotlinBuild", + d8EnvSpec, + d8Root +) + +with(d8KotlinBuild) { + d8EnvSpec.version.set(project.v8Version) + + @Suppress("DEPRECATION") + d8Root.version = project.v8Version +} \ No newline at end of file diff --git a/repo/gradle-build-conventions/d8-configuration/src/main/kotlin/org/jetbrains/kotlin/build/d8/D8Extension.kt b/repo/gradle-build-conventions/d8-configuration/src/main/kotlin/org/jetbrains/kotlin/build/d8/D8Extension.kt new file mode 100644 index 0000000000000..2d8264a7ea043 --- /dev/null +++ b/repo/gradle-build-conventions/d8-configuration/src/main/kotlin/org/jetbrains/kotlin/build/d8/D8Extension.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2024 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. + */ + +@file:OptIn(ExperimentalWasmDsl::class) + +package org.jetbrains.kotlin.build.d8 + +import org.gradle.api.Project +import org.gradle.api.tasks.testing.Test +import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.targets.js.d8.D8EnvSpec +import org.jetbrains.kotlin.gradle.targets.js.d8.D8RootExtension + +abstract class D8Extension( + private val d8envSpec: D8EnvSpec, + private val d8Root: D8RootExtension +) { + val Project.v8Version: String get() = property("versions.v8") as String + + fun Test.setupV8() { + with(d8envSpec) { + dependsOn(project.d8SetupTaskProvider) + } + dependsOn(d8Root.setupTaskProvider) + val v8ExecutablePath = project.provider { + d8Root.requireConfigured().executablePath.absolutePath + } + doFirst { + systemProperty("javascript.engine.path.V8", v8ExecutablePath.get()) + } + } + +} \ No newline at end of file diff --git a/repo/gradle-build-conventions/settings.gradle.kts b/repo/gradle-build-conventions/settings.gradle.kts index cd2b7221819d2..01bcaf9cd03aa 100644 --- a/repo/gradle-build-conventions/settings.gradle.kts +++ b/repo/gradle-build-conventions/settings.gradle.kts @@ -34,4 +34,5 @@ include(":android-sdk-provisioner") include(":asm-deprecating-transformer") include(":binary-compatibility-extended") include(":gradle-plugins-documentation") -include(":gradle-plugins-common") \ No newline at end of file +include(":gradle-plugins-common") +include(":d8-configuration") \ No newline at end of file diff --git a/wasm/wasm.tests/build.gradle.kts b/wasm/wasm.tests/build.gradle.kts index e5713792eeb10..af23c161992de 100644 --- a/wasm/wasm.tests/build.gradle.kts +++ b/wasm/wasm.tests/build.gradle.kts @@ -1,6 +1,7 @@ import org.gradle.internal.os.OperatingSystem import java.net.URI import com.github.gradle.node.npm.task.NpmTask +import org.jetbrains.kotlin.build.d8.D8Extension import java.nio.file.Files import java.util.* @@ -8,6 +9,7 @@ plugins { kotlin("jvm") id("jps-compatible") alias(libs.plugins.gradle.node) + id("d8-configuration") } node { @@ -122,7 +124,6 @@ dependencies { val generationRoot = projectDir.resolve("tests-gen") -useD8Plugin() useNodeJsPlugin() useBinaryenPlugin() optInToExperimentalCompilerApi() @@ -278,7 +279,9 @@ fun Project.wasmProjectTest( jUnitMode = JUnitMode.JUnit5 ) { workingDir = rootDir - setupV8() + with(project.the()) { + setupV8() + } setupNodeJs() setupBinaryen() setupSpiderMonkey()