From 6d125e0880be34f19fab1d72571105356aabe951 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Fri, 26 Mar 2021 16:19:05 +0100 Subject: [PATCH] Initial implementation of kotlin + intellij combined repo --- buildSrc/src/main/kotlin/artifacts.kt | 25 ++++++ buildSrc/src/main/kotlin/dependencies.kt | 83 +++++++++++++++++++ .../build.gradle.kts | 8 +- .../build.gradle.kts | 8 +- .../build.gradle.kts | 8 +- .../build.gradle.kts | 14 ++-- .../build.gradle.kts | 8 +- .../build.gradle.kts | 8 +- .../kotlin-compiler-for-ide/build.gradle.kts | 54 ++++++------ .../build.gradle.kts | 8 +- .../build.gradle.kts | 8 +- .../build.gradle.kts | 8 +- .../build.gradle.kts | 12 ++- .../build.gradle.kts | 8 +- settings.gradle | 17 ++++ 15 files changed, 211 insertions(+), 66 deletions(-) diff --git a/buildSrc/src/main/kotlin/artifacts.kt b/buildSrc/src/main/kotlin/artifacts.kt index 155a9d64b61..fb5645b203f 100644 --- a/buildSrc/src/main/kotlin/artifacts.kt +++ b/buildSrc/src/main/kotlin/artifacts.kt @@ -236,6 +236,31 @@ fun Project.idePluginDependency(block: () -> Unit) { } } +fun Project.publishJarsForIde(projects: List, libraryDependencies: List = emptyList()) { + idePluginDependency { + publishProjectJars(projects, libraryDependencies) + } + dependencies { + projects.forEach { + jpsLikeJarDependency(project(it), JpsDepScope.COMPILE, { isTransitive = false }, exported = true) + } + libraryDependencies.forEach { + jpsLikeJarDependency(it, JpsDepScope.COMPILE, exported = true) + } + } +} + +fun Project.publishTestJarsForIde(projectNames: List) { + idePluginDependency { + publishTestJar(projectNames) + } + dependencies { + for (projectName in projectNames) { + jpsLikeJarDependency(projectTests(projectName), JpsDepScope.COMPILE, exported = true) + } + } +} + fun Project.publishProjectJars(projects: List, libraryDependencies: List = emptyList()) { apply() diff --git a/buildSrc/src/main/kotlin/dependencies.kt b/buildSrc/src/main/kotlin/dependencies.kt index e8b2f6ced96..85b8ed156e7 100644 --- a/buildSrc/src/main/kotlin/dependencies.kt +++ b/buildSrc/src/main/kotlin/dependencies.kt @@ -11,11 +11,13 @@ import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ExternalModuleDependency +import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.FileCollection import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo +import org.gradle.kotlin.dsl.closureOf import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.project import java.io.File @@ -115,6 +117,87 @@ fun DependencyHandler.projectTests(name: String): ProjectDependency = project(na fun DependencyHandler.projectRuntimeJar(name: String): ProjectDependency = project(name, configuration = "runtimeJar") fun DependencyHandler.projectArchives(name: String): ProjectDependency = project(name, configuration = "archives") +enum class JpsDepScope { + COMPILE, TEST, RUNTIME, PROVIDED +} + +fun DependencyHandler.add(configurationName: String, dependencyNotation: Any, configure: (ModuleDependency.() -> Unit)?) { + // Avoid `dependencyNotation` to `ModuleDependency` class cast exception if possible + if (configure != null) { + add(configurationName, dependencyNotation, closureOf(configure)) + } else { + add(configurationName, dependencyNotation) + } +} + +fun DependencyHandler.jpsLikeJarDependency( + dependencyNotation: Any, + scope: JpsDepScope, + dependencyConfiguration: (ModuleDependency.() -> Unit)? = null, + exported: Boolean = false +) { + when (scope) { + JpsDepScope.COMPILE -> { + if (exported) { + add("api", dependencyNotation, dependencyConfiguration) + add("testCompile", dependencyNotation, dependencyConfiguration) + } else { + add("implementation", dependencyNotation, dependencyConfiguration) + } + } + JpsDepScope.TEST -> { + if (exported) { + add("testCompile", dependencyNotation, dependencyConfiguration) + } else { + add("testImplementation", dependencyNotation, dependencyConfiguration) + } + } + JpsDepScope.RUNTIME -> { + add("testRuntimeOnly", dependencyNotation, dependencyConfiguration) + } + JpsDepScope.PROVIDED -> { + if (exported) { + add("compileOnlyApi", dependencyNotation, dependencyConfiguration) + add("testCompile", dependencyNotation, dependencyConfiguration) + } else { + add("compileOnly", dependencyNotation, dependencyConfiguration) + add("testImplementation", dependencyNotation, dependencyConfiguration) + } + } + } +} + +fun DependencyHandler.jpsLikeModuleDependency(moduleName: String, scope: JpsDepScope, exported: Boolean = false) { + jpsLikeJarDependency(project(moduleName), scope, exported = exported) + when (scope) { + JpsDepScope.COMPILE -> { + if (exported) { + add("testCompile", projectTests(moduleName)) + } else { + add("testImplementation", projectTests(moduleName)) + } + } + JpsDepScope.TEST -> { + if (exported) { + add("testCompile", projectTests(moduleName)) + } else { + add("testImplementation", projectTests(moduleName)) + } + } + JpsDepScope.RUNTIME -> { + add("runtimeOnly", projectTests(moduleName)) + } + JpsDepScope.PROVIDED -> { + if (exported) { + add("testCompile", projectTests(moduleName)) + } else { + add("testImplementation", projectTests(moduleName)) + } + } + } +} + + fun Project.testApiJUnit5( vintageEngine: Boolean = false, runner: Boolean = false, diff --git a/prepare/ide-plugin-dependencies/allopen-compiler-plugin-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/allopen-compiler-plugin-for-ide/build.gradle.kts index 4b231f1b50c..9cc86d4f530 100644 --- a/prepare/ide-plugin-dependencies/allopen-compiler-plugin-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/allopen-compiler-plugin-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishProjectJars(listOf(":kotlin-allopen-compiler-plugin")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishJarsForIde(listOf(":kotlin-allopen-compiler-plugin")) diff --git a/prepare/ide-plugin-dependencies/allopen-compiler-plugin-tests-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/allopen-compiler-plugin-tests-for-ide/build.gradle.kts index bd54a23bc6e..50006d6f82f 100644 --- a/prepare/ide-plugin-dependencies/allopen-compiler-plugin-tests-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/allopen-compiler-plugin-tests-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishTestJar(listOf(":compiler:incremental-compilation-impl")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishTestJarsForIde(listOf(":compiler:incremental-compilation-impl")) diff --git a/prepare/ide-plugin-dependencies/android-extensions-compiler-plugin-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/android-extensions-compiler-plugin-for-ide/build.gradle.kts index c9c5faa5ffe..99a061136b8 100644 --- a/prepare/ide-plugin-dependencies/android-extensions-compiler-plugin-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/android-extensions-compiler-plugin-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishProjectJars(listOf(":plugins:android-extensions-compiler")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishJarsForIde(listOf(":plugins:android-extensions-compiler")) diff --git a/prepare/ide-plugin-dependencies/compiler-components-for-jps/build.gradle.kts b/prepare/ide-plugin-dependencies/compiler-components-for-jps/build.gradle.kts index e250dafeba5..2f1abf3e52a 100644 --- a/prepare/ide-plugin-dependencies/compiler-components-for-jps/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/compiler-components-for-jps/build.gradle.kts @@ -1,8 +1,10 @@ -idePluginDependency { - @Suppress("UNCHECKED_CAST") - val compilerComponents = rootProject.extra["compilerModulesForJps"] as List +plugins { + kotlin("jvm") +} - val otherProjects = listOf(":kotlin-daemon-client") +@Suppress("UNCHECKED_CAST") +val compilerComponents = rootProject.extra["compilerModulesForJps"] as List - publishProjectJars(compilerComponents + otherProjects) -} \ No newline at end of file +val otherProjects = listOf(":kotlin-daemon-client") + +publishJarsForIde(compilerComponents + otherProjects) diff --git a/prepare/ide-plugin-dependencies/incremental-compilation-impl-tests-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/incremental-compilation-impl-tests-for-ide/build.gradle.kts index bd54a23bc6e..50006d6f82f 100644 --- a/prepare/ide-plugin-dependencies/incremental-compilation-impl-tests-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/incremental-compilation-impl-tests-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishTestJar(listOf(":compiler:incremental-compilation-impl")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishTestJarsForIde(listOf(":compiler:incremental-compilation-impl")) diff --git a/prepare/ide-plugin-dependencies/kotlin-build-common-tests-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/kotlin-build-common-tests-for-ide/build.gradle.kts index 21033e830bf..3b87eb9938b 100644 --- a/prepare/ide-plugin-dependencies/kotlin-build-common-tests-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/kotlin-build-common-tests-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishTestJar(listOf(":kotlin-build-common")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishTestJarsForIde(listOf(":kotlin-build-common")) diff --git a/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts index ad54b0ad45f..c4f63766751 100644 --- a/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts @@ -1,27 +1,29 @@ -idePluginDependency { - val compilerModules: Array by rootProject.extra - - val excludedCompilerModules = listOf( - ":compiler:cli", - ":compiler:cli-js", - ":compiler:javac-wrapper", - ":compiler:backend.js", - ":compiler:backend.wasm", - ":js:js.dce", - ":compiler:ir.serialization.js", - ":compiler:incremental-compilation-impl", - ":compiler:fir:raw-fir:light-tree2fir" - ) - - val projects = compilerModules.asList() - excludedCompilerModules + listOf( - ":kotlin-compiler-runner", - ":kotlin-preloader", - ":daemon-common", - ":kotlin-daemon-client" - ) - - publishProjectJars( - projects = projects, - libraryDependencies = listOf(protobufFull()) - ) +plugins { + kotlin("jvm") } + +val compilerModules: Array by rootProject.extra + +val excludedCompilerModules = listOf( + ":compiler:cli", + ":compiler:cli-js", + ":compiler:javac-wrapper", + ":compiler:backend.js", + ":compiler:backend.wasm", + ":js:js.dce", + ":compiler:ir.serialization.js", + ":compiler:incremental-compilation-impl", + ":compiler:fir:raw-fir:light-tree2fir" +) + +val projects = compilerModules.asList() - excludedCompilerModules + listOf( + ":kotlin-compiler-runner", + ":kotlin-preloader", + ":daemon-common", + ":kotlin-daemon-client" +) + +publishJarsForIde( + projects = projects, + libraryDependencies = listOf(protobufFull()) +) diff --git a/prepare/ide-plugin-dependencies/kotlin-gradle-statistics-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/kotlin-gradle-statistics-for-ide/build.gradle.kts index 1056cf4b9f7..885ce973cd9 100644 --- a/prepare/ide-plugin-dependencies/kotlin-gradle-statistics-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/kotlin-gradle-statistics-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishProjectJars(listOf(":kotlin-gradle-statistics")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishJarsForIde(listOf(":kotlin-gradle-statistics")) diff --git a/prepare/ide-plugin-dependencies/kotlinx-serialization-compiler-plugin-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/kotlinx-serialization-compiler-plugin-for-ide/build.gradle.kts index 27d89dbc80c..20127ac3684 100644 --- a/prepare/ide-plugin-dependencies/kotlinx-serialization-compiler-plugin-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/kotlinx-serialization-compiler-plugin-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishProjectJars(listOf(":kotlinx-serialization-compiler-plugin")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishJarsForIde(listOf(":kotlinx-serialization-compiler-plugin")) diff --git a/prepare/ide-plugin-dependencies/noarg-compiler-plugin-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/noarg-compiler-plugin-for-ide/build.gradle.kts index 51bcf4a17c3..2e256c4f96b 100644 --- a/prepare/ide-plugin-dependencies/noarg-compiler-plugin-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/noarg-compiler-plugin-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishProjectJars(listOf(":kotlin-noarg-compiler-plugin")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishJarsForIde(listOf(":kotlin-noarg-compiler-plugin")) diff --git a/prepare/ide-plugin-dependencies/parcelize-compiler-plugin-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/parcelize-compiler-plugin-for-ide/build.gradle.kts index 8336bd18479..ca1a2f89dd2 100644 --- a/prepare/ide-plugin-dependencies/parcelize-compiler-plugin-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/parcelize-compiler-plugin-for-ide/build.gradle.kts @@ -1,7 +1,5 @@ -idePluginDependency { - publishProjectJars( - listOf( - ":plugins:parcelize:parcelize-compiler" - ) - ) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishJarsForIde(listOf(":plugins:parcelize:parcelize-compiler")) diff --git a/prepare/ide-plugin-dependencies/sam-with-receiver-compiler-plugin-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/sam-with-receiver-compiler-plugin-for-ide/build.gradle.kts index 0cb7783d796..b4a0103b8ff 100644 --- a/prepare/ide-plugin-dependencies/sam-with-receiver-compiler-plugin-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/sam-with-receiver-compiler-plugin-for-ide/build.gradle.kts @@ -1,3 +1,5 @@ -idePluginDependency { - publishProjectJars(listOf(":kotlin-sam-with-receiver-compiler-plugin")) -} \ No newline at end of file +plugins { + kotlin("jvm") +} + +publishJarsForIde(listOf(":kotlin-sam-with-receiver-compiler-plugin")) diff --git a/settings.gradle b/settings.gradle index a005b599a76..656380ca27f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -382,6 +382,23 @@ include ":prepare:ide-plugin-dependencies:android-extensions-compiler-plugin-for ":prepare:ide-plugin-dependencies:compiler-components-for-jps", ":prepare:ide-plugin-dependencies:kotlin-compiler-tests-for-ide" +if (buildProperties.getBoolean("attachedIntellijVersion", false)) { + logger.info("Including kotlin-ide modules in settings.gradle") + new File(rootDir, "kotlin-ide").eachFileRecurse { + String fileName = it.name + if (fileName.endsWith(".iml") && fileName.startsWith("kotlin.") && new File(it.parentFile, "build.gradle.kts").exists() || + fileName == "intellij.platform.debugger.testFramework.iml" || fileName == "intellij.gradle.tests.iml" || + fileName == "intellij.platform.externalSystem.tests.iml" || fileName == "intellij.platform.lang.tests.iml" || + fileName == "intellij.platform.testExtensions.iml" || fileName == "intellij.java.compiler.tests.iml" || + fileName == "intellij.gradle.toolingExtension.tests.iml" + ) { + String projectName = ":kotlin-ide.${fileName.substring(0, fileName.length() - ".iml".length())}" + include(projectName) + project(projectName).projectDir = it.parentFile + } + } +} + if (buildProperties.includeCidrPlugins) { logger.info("Including CIDR modules in settings.gradle") include ":kotlin-ultimate:ide:cidr-gradle-tooling",