From 6e65a4810eb19fbda4eef50d636af53574f5ec43 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 22 Feb 2018 21:45:00 +0300 Subject: [PATCH] Make a project-wide embeddedComponents configuration for embedding external binaries to project artifacts --- buildSrc/src/main/kotlin/dependencies.kt | 18 +++++ .../main/kotlin/pill/kotlinPluginArtifact.kt | 13 ++-- .../daemon/daemon-client/build.gradle.kts | 13 ++-- gradle/project-schema.json | 69 ++++++++++++++++--- .../build.gradle.kts | 7 +- plugins/kapt3/kapt3-compiler/build.gradle.kts | 13 ++-- prepare/android-lint/build.gradle.kts | 11 +-- prepare/compiler/build.gradle.kts | 1 - prepare/jps-plugin/build.gradle.kts | 8 +-- 9 files changed, 116 insertions(+), 37 deletions(-) diff --git a/buildSrc/src/main/kotlin/dependencies.kt b/buildSrc/src/main/kotlin/dependencies.kt index 1a1f0be3ec1..953fe57aa72 100644 --- a/buildSrc/src/main/kotlin/dependencies.kt +++ b/buildSrc/src/main/kotlin/dependencies.kt @@ -5,6 +5,8 @@ import org.gradle.api.Project import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.file.ConfigurableFileCollection +import org.gradle.api.tasks.AbstractCopyTask +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.project import java.io.File @@ -98,3 +100,19 @@ fun firstFromJavaHomeThatExists(vararg paths: String): File? = fun toolsJar(): File? = firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar") +object EmbeddedComponents { + val CONFIGURATION_NAME = "embeddedComponents" +} + +fun Project.containsEmbeddedComponents() { + configurations.create(EmbeddedComponents.CONFIGURATION_NAME) +} + +fun AbstractCopyTask.fromEmbeddedComponents() { + val embeddedComponents = project.configurations.getByName(EmbeddedComponents.CONFIGURATION_NAME) + if (this is ShadowJar) { + from(embeddedComponents) + } else { + embeddedComponents.forEach { from(if (it.isDirectory) it else project.zipTree(it)) } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt b/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt index bb87dfe2206..6053d911cb9 100644 --- a/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt +++ b/buildSrc/src/main/kotlin/pill/kotlinPluginArtifact.kt @@ -107,7 +107,10 @@ fun generateKotlinPluginArtifactFile(rootProject: Project): PFile { val root = Root() // Copy kotlinc directory - root.add(DirectoryCopy(File(rootProject.extra["distKotlinHomeDir"].toString()))) + root.add(Directory("kotlinc").apply { + val kotlincDirectory = rootProject.extra["distKotlinHomeDir"].toString() + add(DirectoryCopy(File(kotlincDirectory))) + }) for (task in ideaPluginTasks) { val spec = task.rootSpec.children.filterIsInstance().singleOrNull() @@ -146,11 +149,11 @@ fun generateKotlinPluginArtifactFile(rootProject: Project): PFile { root.getDirectory(targetDir).add(this) } - val fatJarContentsConfiguration = sourcePath.project.configurations - .findByName("fatJarContents")?.resolvedConfiguration + val embeddedComponents = sourcePath.project.configurations + .findByName(EmbeddedComponents.CONFIGURATION_NAME)?.resolvedConfiguration - if (fatJarContentsConfiguration != null) { - for ((_, _, dependency) in listOf(fatJarContentsConfiguration to Scope.COMPILE).collectDependencies()) { + if (embeddedComponents != null) { + for ((_, _, dependency) in listOf(embeddedComponents to Scope.COMPILE).collectDependencies()) { if (dependency.configuration == "runtimeElements") { archiveForJar.add(ModuleOutput(dependency.moduleName + ".src")) } else if (dependency.configuration == "tests-jar" || dependency.configuration == "jpsTest") { diff --git a/compiler/daemon/daemon-client/build.gradle.kts b/compiler/daemon/daemon-client/build.gradle.kts index 89b80ac17a8..16604b5680a 100644 --- a/compiler/daemon/daemon-client/build.gradle.kts +++ b/compiler/daemon/daemon-client/build.gradle.kts @@ -9,8 +9,7 @@ jvmTarget = "1.6" val nativePlatformVariants: List by rootProject.extra -// Do not rename, used in JPS importer -val fatJarContents by configurations.creating +containsEmbeddedComponents() dependencies { compileOnly(project(":compiler:util")) @@ -18,10 +17,11 @@ dependencies { compileOnly(project(":compiler:daemon-common")) compileOnly(project(":kotlin-reflect-api")) compileOnly(commonDep("net.rubygrapefruit", "native-platform")) - fatJarContents(project(":compiler:daemon-common")) { isTransitive = false } - fatJarContents(commonDep("net.rubygrapefruit", "native-platform")) + + embeddedComponents(project(":compiler:daemon-common")) { isTransitive = false } + embeddedComponents(commonDep("net.rubygrapefruit", "native-platform")) nativePlatformVariants.forEach { - fatJarContents(commonDep("net.rubygrapefruit", "native-platform", "-$it")) + embeddedComponents(commonDep("net.rubygrapefruit", "native-platform", "-$it")) } } @@ -32,8 +32,9 @@ sourceSets { runtimeJar(task("shadowJar")) { from(the().sourceSets.getByName("main").output) - from(fatJarContents) + fromEmbeddedComponents() } + sourcesJar() javadocJar() diff --git a/gradle/project-schema.json b/gradle/project-schema.json index d2c4b243069..ef2ae0dcda0 100644 --- a/gradle/project-schema.json +++ b/gradle/project-schema.json @@ -58,6 +58,7 @@ "configurations": [ "archives", "default", + "embeddedComponents", "runtimeJar" ], "extensions": { @@ -199,8 +200,7 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly", - "tests-jar" + "testRuntimeOnly" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -545,6 +545,7 @@ "compileOnly", "default", "distJar", + "embeddedComponents", "implementation", "jpsTest", "kapt", @@ -1009,7 +1010,7 @@ "compileOnly", "default", "distJar", - "fatJarContents", + "embeddedComponents", "implementation", "jpsTest", "kapt", @@ -1242,7 +1243,7 @@ "configurations": [ "archives", "default", - "fatJarContents", + "embeddedComponents", "runtimeJar" ], "extensions": { @@ -1751,10 +1752,18 @@ "compileOnly", "default", "distJar", + "experimentalCompile", + "experimentalCompileClasspath", + "experimentalCompileOnly", + "experimentalImplementation", + "experimentalRuntime", + "experimentalRuntimeClasspath", + "experimentalRuntimeOnly", "implementation", "kapt", "kaptAnnotations", "kaptBuiltins", + "kaptExperimental", "kaptTest", "mainJar", "runtime", @@ -1992,6 +2001,13 @@ "compileOnly", "default", "distJar", + "experimentalCompile", + "experimentalCompileClasspath", + "experimentalCompileOnly", + "experimentalImplementation", + "experimentalRuntime", + "experimentalRuntimeClasspath", + "experimentalRuntimeOnly", "implementation", "merger", "nodeDist", @@ -2970,7 +2986,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -3006,7 +3023,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -3863,7 +3881,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "tests-jar" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", @@ -3910,6 +3929,38 @@ "reporting": "org.gradle.api.reporting.ReportingExtension" } }, + ":jps-plugin:jps-services-declarations": { + "conventions": { + "base": "org.gradle.api.plugins.BasePluginConvention", + "java": "org.gradle.api.plugins.JavaPluginConvention" + }, + "configurations": [ + "apiElements", + "archives", + "compile", + "compileClasspath", + "compileOnly", + "default", + "implementation", + "jpsTest", + "runtime", + "runtimeClasspath", + "runtimeElements", + "runtimeOnly", + "testCompile", + "testCompileClasspath", + "testCompileOnly", + "testImplementation", + "testRuntime", + "testRuntimeClasspath", + "testRuntimeOnly" + ], + "extensions": { + "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", + "defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet", + "reporting": "org.gradle.api.reporting.ReportingExtension" + } + }, ":js:js.ast": { "conventions": { "base": "org.gradle.api.plugins.BasePluginConvention", @@ -4586,6 +4637,7 @@ "compileOnly", "default", "distJar", + "embeddedComponents", "implementation", "jpsTest", "kapt", @@ -4940,7 +4992,8 @@ "testImplementation", "testRuntime", "testRuntimeClasspath", - "testRuntimeOnly" + "testRuntimeOnly", + "versions" ], "extensions": { "ext": "org.gradle.api.plugins.ExtraPropertiesExtension", diff --git a/plugins/android-extensions/android-extensions-compiler/build.gradle.kts b/plugins/android-extensions/android-extensions-compiler/build.gradle.kts index e041caea383..df48a7747e2 100644 --- a/plugins/android-extensions/android-extensions-compiler/build.gradle.kts +++ b/plugins/android-extensions/android-extensions-compiler/build.gradle.kts @@ -6,8 +6,7 @@ apply { plugin("jps-compatible") } val robolectricClasspath by configurations.creating -// Do not rename, used in JPS importer -val fatJarContents by configurations.creating +containsEmbeddedComponents() dependencies { testCompile(intellijCoreDep()) { includeJars("intellij-core") } @@ -34,7 +33,7 @@ dependencies { robolectricClasspath(commonDep("org.robolectric", "robolectric")) - fatJarContents(project(":kotlin-android-extensions-runtime")) + embeddedComponents(project(":kotlin-android-extensions-runtime")) { isTransitive = false } } sourceSets { @@ -43,7 +42,7 @@ sourceSets { } runtimeJar { - from(getSourceSetsFrom(":kotlin-android-extensions-runtime")["main"].output.classesDirs) + fromEmbeddedComponents() } dist() diff --git a/plugins/kapt3/kapt3-compiler/build.gradle.kts b/plugins/kapt3/kapt3-compiler/build.gradle.kts index d195374b731..6644782b3be 100644 --- a/plugins/kapt3/kapt3-compiler/build.gradle.kts +++ b/plugins/kapt3/kapt3-compiler/build.gradle.kts @@ -4,6 +4,8 @@ description = "Annotation Processor for Kotlin" apply { plugin("kotlin") } apply { plugin("jps-compatible") } +containsEmbeddedComponents() + dependencies { testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") } testRuntime(intellijDep()) @@ -23,6 +25,8 @@ dependencies { testCompile(projectTests(":compiler:tests-common")) testCompile(commonDep("junit:junit")) testCompile(project(":kotlin-annotation-processing-runtime")) + + embeddedComponents(project(":kotlin-annotation-processing-runtime")) { isTransitive = false } } sourceSets { @@ -30,10 +34,6 @@ sourceSets { "test" { projectDefault() } } -runtimeJar { - from(getSourceSetsFrom(":kotlin-annotation-processing-runtime")["main"].output.classesDirs) -} - testsJar {} projectTest { @@ -41,7 +41,10 @@ projectTest { dependsOn(":dist") } -runtimeJar() +runtimeJar { + fromEmbeddedComponents() +} + sourcesJar() javadocJar() diff --git a/prepare/android-lint/build.gradle.kts b/prepare/android-lint/build.gradle.kts index b0d007e1e11..1e2cdac74bf 100644 --- a/prepare/android-lint/build.gradle.kts +++ b/prepare/android-lint/build.gradle.kts @@ -13,16 +13,19 @@ sourceSets { "test" {} } -// Do not rename, used in JPS importer -val fatJarContents by configurations.creating +containsEmbeddedComponents() dependencies { - projectsToShadow.forEach {p -> - fatJarContents(project(p)) { isTransitive = false } + projectsToShadow.forEach { p -> + embeddedComponents(project(p)) { isTransitive = false } } } runtimeJar { + /* + TODO: `fromEmbeddedComponents()` should be used here. + Couldn't use it because of the "must be locked before it can be used to compute a classpath" error. + */ projectsToShadow.forEach { dependsOn("$it:classes") project(it).let { p -> diff --git a/prepare/compiler/build.gradle.kts b/prepare/compiler/build.gradle.kts index 652175b4e65..8b7357af8bf 100644 --- a/prepare/compiler/build.gradle.kts +++ b/prepare/compiler/build.gradle.kts @@ -23,7 +23,6 @@ val shrink = val compilerManifestClassPath = "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar" -// Do not rename, used in JPS importer val fatJarContents by configurations.creating val fatJarContentsStripMetadata by configurations.creating diff --git a/prepare/jps-plugin/build.gradle.kts b/prepare/jps-plugin/build.gradle.kts index 3345c6ba528..741a833e7f9 100644 --- a/prepare/jps-plugin/build.gradle.kts +++ b/prepare/jps-plugin/build.gradle.kts @@ -21,20 +21,20 @@ val projectsToShadow = listOf( ":core:util.runtime", ":plugins:android-extensions-jps") -// Do not rename, used in JPS importer -val fatJarContents by configurations.creating + +containsEmbeddedComponents() dependencies { projectsToShadow.forEach { - fatJarContents(project(it)) { isTransitive = false } + embeddedComponents(project(it)) { isTransitive = false } } } runtimeJar(task("jar")) { manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.runner.Main") manifest.attributes.put("Class-Path", "kotlin-stdlib.jar") - from(fatJarContents) from(files("$rootDir/resources/kotlinManifest.properties")) + fromEmbeddedComponents() } ideaPlugin("lib/jps")