From e18b77af2179cb7046578f4dd7f3f7f787a087c6 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Mon, 11 Sep 2017 13:03:35 +0200 Subject: [PATCH] Refactor compiler-related published projects - move preparation into separate projects - rename projects for publishing - add compiler plugins --- build.gradle.kts | 4 + compiler/build.gradle.kts | 158 +----------------- idea/build.gradle.kts | 6 +- libraries/tools/kotlin-allopen/build.gradle | 4 +- libraries/tools/kotlin-noarg/build.gradle | 2 +- .../kotlin-sam-with-receiver/build.gradle | 2 +- plugins/allopen/allopen-cli/build.gradle.kts | 20 ++- plugins/allopen/allopen-ide/build.gradle.kts | 2 +- plugins/noarg/noarg-cli/build.gradle.kts | 24 +-- plugins/noarg/noarg-ide/build.gradle.kts | 2 +- plugins/plugins-tests/build.gradle.kts | 6 +- .../sam-with-receiver-cli/build.gradle.kts | 24 ++- .../sam-with-receiver-ide/build.gradle.kts | 2 +- .../source-sections-compiler/build.gradle.kts | 21 ++- .../build.gradle.kts | 60 +------ prepare/compiler-embeddable/build.gradle.kts | 26 ++- prepare/compiler/build.gradle.kts | 145 +++++++++------- prepare/daemon-client/build.gradle.kts | 31 ++++ settings.gradle | 31 ++-- 19 files changed, 228 insertions(+), 342 deletions(-) create mode 100644 prepare/daemon-client/build.gradle.kts diff --git a/build.gradle.kts b/build.gradle.kts index df8927efdd0..ac15a38b956 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -176,6 +176,10 @@ allprojects { kotlinOptions.freeCompilerArgs = listOf("-Xallow-kotlin-package", "-module-name", project.name) } + tasks.withType { + enabled = false + } + task("javadocJar") { classifier = "javadoc" } diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index cffdd8360d0..10c837b66aa 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -1,70 +1,11 @@ import java.io.File -import proguard.gradle.ProGuardTask -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -import org.gradle.api.file.DuplicatesStrategy -import org.gradle.api.internal.plugins.DslObject -import org.gradle.api.publication.maven.internal.deployer.MavenRemoteRepository - -buildscript { - repositories { - jcenter() - } - - dependencies { - classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3") - classpath("net.sf.proguard:proguard-gradle:5.3.1") - } -} apply { plugin("kotlin") } -plugins { - maven -} -//apply { plugin("maven") } - - -// Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build -val shrink = true - -val compilerManifestClassPath = - "kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar" - -val fatJarContents by configurations.creating -val proguardLibraryJars by configurations.creating -val fatJar by configurations.creating -val compilerJar by configurations.creating -val embeddableCompilerJar by configurations.creating - -val compilerBaseName: String by rootProject.extra -val embeddableCompilerBaseName: String by rootProject.extra - -val javaHome = File(System.getProperty("java.home")) - -val buildLocalRepoPath: File by rootProject.extra - val compilerModules: Array by rootProject.extra val otherCompilerModules = compilerModules.filter { it != path } -val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin" - -val packagesToRelocate = - listOf("com.intellij", - "com.google", - "com.sampullara", - "org.apache", - "org.jdom", - "org.picocontainer", - "jline", - "gnu", - "javax.inject", - "org.fusesource") - -fun firstFromJavaHomeThatExists(vararg paths: String): File = - paths.mapNotNull { File(javaHome, it).takeIf { it.exists() } }.firstOrNull() - ?: throw GradleException("Cannot find under '$javaHome' neither of: ${paths.joinToString()}") - dependencies { val compile by configurations val compileOnly by configurations @@ -95,37 +36,12 @@ dependencies { testCompile(project(":ant")) otherCompilerModules.forEach { testCompile(project(it)) - fatJarContents(project(it)) { isTransitive = false } } testRuntime(ideaSdkCoreDeps("*.jar")) testRuntime(ideaSdkDeps("*.jar")) -// testRuntime(project(":prepare:compiler", configuration = "default")) +// testRuntime(project(":kotlin-compiler", configuration = "default")) buildVersion() - - fatJarContents(project(":core:builtins", configuration = "builtins")) - fatJarContents(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) - fatJarContents(ideaSdkDeps("jna-platform", "oromatcher")) - fatJarContents(ideaSdkDeps("jps-model.jar", subdir = "jps")) - fatJarContents(commonDep("javax.inject")) - fatJarContents(commonDep("org.jline", "jline")) - fatJarContents(protobufFull()) - fatJarContents(commonDep("com.github.spullara.cli-parser", "cli-parser")) - fatJarContents(commonDep("com.google.code.findbugs", "jsr305")) - fatJarContents(commonDep("io.javaslang", "javaslang")) - fatJarContents(preloadedDeps("json-org")) - - proguardLibraryJars(files(firstFromJavaHomeThatExists("lib/rt.jar", "../Classes/classes.jar"), - firstFromJavaHomeThatExists("lib/jsse.jar", "../Classes/jsse.jar"), - firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar"))) - proguardLibraryJars(project(":kotlin-stdlib", configuration = "mainJar")) - proguardLibraryJars(project(":kotlin-script-runtime", configuration = "mainJar")) - proguardLibraryJars(project(":kotlin-reflect", configuration = "mainJar")) - proguardLibraryJars(preloadedDeps("kotlinx-coroutines-core")) - -// proguardLibraryJars(project(":prepare:runtime", configuration = "default").apply { isTransitive = false }) -// proguardLibraryJars(project(":prepare:reflect", configuration = "default").apply { isTransitive = false }) -// proguardLibraryJars(project(":core:script.runtime").apply { isTransitive = false }) } configureKotlinProjectSources( @@ -153,75 +69,3 @@ tasks.withType { ignoreFailures = true } -val packCompiler by task { - configurations = listOf(fatJar) - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - destinationDir = File(buildDir, "libs") - baseName = compilerBaseName - classifier = "before-proguard" - dependsOn(protobufFullTask) - - setupRuntimeJar("Kotlin Compiler") - from(getCompiledClasses()) - from(fatJarContents) - - manifest.attributes.put("Class-Path", compilerManifestClassPath) - manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") -} - -val proguard by task { - dependsOn(packCompiler) - configuration("$rootDir/compiler/compiler.pro") - - val outputJar = File(buildDir, "libs", "$compilerBaseName-after-proguard.jar") - - inputs.files(packCompiler.outputs.files.singleFile) - outputs.file(outputJar) - - // TODO: remove after dropping compatibility with ant build - doFirst { - System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.outputs.files.singleFile.canonicalPath) - System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath) - } - - libraryjars(proguardLibraryJars) - printconfiguration("$buildDir/compiler.pro.dump") -} - -val embeddable by task { - destinationDir = File(buildDir, "libs") - baseName = embeddableCompilerBaseName - configurations = listOf(embeddableCompilerJar) - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - dependsOn(proguard) - from(proguard) - relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf") - packagesToRelocate.forEach { - relocate(it, "$kotlinEmbeddableRootPackage.$it") - } - relocate("org.fusesource", "$kotlinEmbeddableRootPackage.org.fusesource") { - // TODO: remove "it." after #KT-12848 get addressed - exclude("org.fusesource.jansi.internal.CLibrary") - } -} - -dist { - if (shrink) { - from(proguard) - } else { - from(packCompiler) - } - rename(".*", compilerBaseName + ".jar") -} - -artifacts.add(compilerJar.name, proguard.outputs.files.singleFile) { - builtBy(proguard) - classifier = "" - name = compilerBaseName -} -artifacts.add(embeddableCompilerJar.name, embeddable.outputs.files.singleFile) { - builtBy(embeddable) - classifier = "" - name = embeddableCompilerBaseName -} - diff --git a/idea/build.gradle.kts b/idea/build.gradle.kts index 4d59944bdc1..91b8207b13c 100644 --- a/idea/build.gradle.kts +++ b/idea/build.gradle.kts @@ -79,12 +79,12 @@ dependencies { testCompile(project(":plugins:android-extensions-compiler")) testCompile(project(":plugins:android-extensions-idea")) { isTransitive = false } testCompile(project(":plugins:allopen-ide")) { isTransitive = false } - testCompile(project(":plugins:allopen-cli")) + testCompile(project(":kotlin-allopen-compiler-plugin")) testCompile(project(":plugins:noarg-ide")) { isTransitive = false } - testCompile(project(":plugins:noarg-cli")) + testCompile(project(":kotlin-noarg-compiler-plugin")) testCompile(project(":plugins:annotation-based-compiler-plugins-ide-support")) { isTransitive = false } testCompile(project(":plugins:sam-with-receiver-ide")) { isTransitive = false } - testCompile(project(":plugins:sam-with-receiver-cli")) + testCompile(project(":kotlin-sam-with-receiver-compiler-plugin")) testCompile(project(":idea:idea-android")) { isTransitive = false } testCompile(project(":plugins:lint")) { isTransitive = false } testCompile(project(":plugins:uast-kotlin")) diff --git a/libraries/tools/kotlin-allopen/build.gradle b/libraries/tools/kotlin-allopen/build.gradle index f655ef6fe25..f1d81ff8e1b 100644 --- a/libraries/tools/kotlin-allopen/build.gradle +++ b/libraries/tools/kotlin-allopen/build.gradle @@ -13,8 +13,8 @@ dependencies { compile project(':kotlin-gradle-plugin-api') compile project(':kotlin-stdlib') - compileOnly project(path: ':compiler', configuration: 'embeddableCompilerJar') - compile project(':plugins:allopen-cli') + compileOnly project(path: ':kotlin-compiler-embeddable', configuration: 'runtimeJar') + compile project(':kotlin-allopen-compiler-plugin') compileOnly 'org.jetbrains.kotlin:gradle-api:1.6' } diff --git a/libraries/tools/kotlin-noarg/build.gradle b/libraries/tools/kotlin-noarg/build.gradle index 1e08f7f5121..6399baea270 100644 --- a/libraries/tools/kotlin-noarg/build.gradle +++ b/libraries/tools/kotlin-noarg/build.gradle @@ -20,7 +20,7 @@ dependencies { compile project(':kotlin-stdlib') compileOnly project(':compiler') - compile project(':plugins:noarg-cli') + compile project(':kotlin-noarg-compiler-plugin') compileOnly 'org.jetbrains.kotlin:gradle-api:1.6' } diff --git a/libraries/tools/kotlin-sam-with-receiver/build.gradle b/libraries/tools/kotlin-sam-with-receiver/build.gradle index 827c834c263..67fd5a46fb8 100644 --- a/libraries/tools/kotlin-sam-with-receiver/build.gradle +++ b/libraries/tools/kotlin-sam-with-receiver/build.gradle @@ -20,7 +20,7 @@ dependencies { compile project(':kotlin-stdlib') compileOnly project(':compiler') - compile project(':plugins:sam-with-receiver-cli') + compile project(':kotlin-sam-with-receiver-compiler-plugin') compileOnly 'org.jetbrains.kotlin:gradle-api:1.6' } diff --git a/plugins/allopen/allopen-cli/build.gradle.kts b/plugins/allopen/allopen-cli/build.gradle.kts index ac38a05786c..41bd89f2815 100644 --- a/plugins/allopen/allopen-cli/build.gradle.kts +++ b/plugins/allopen/allopen-cli/build.gradle.kts @@ -1,30 +1,32 @@ -import org.gradle.jvm.tasks.Jar +description = "Kotlin AllOpen Compiler Plugin" apply { plugin("kotlin") } dependencies { - val compile by configurations - compile(ideaSdkCoreDeps("intellij-core")) - compile(project(":compiler:plugin-api")) - compile(project(":compiler:frontend")) + val compileOnly by configurations + val runtime by configurations + compileOnly(ideaSdkCoreDeps("intellij-core")) + compileOnly(project(":compiler:plugin-api")) + compileOnly(project(":compiler:frontend")) + runtime(project(":kotlin-compiler", configuration = "runtimeJar")) + runtime(project(":kotlin-stdlib")) } configureKotlinProjectSourcesDefault() configureKotlinProjectNoTests() -val jar: Jar by tasks -jar.apply { - setupRuntimeJar("Kotlin AllOpen Compiler Plugin") +val jar = runtimeJar { from(fileTree("$projectDir/src")) { include("META-INF/**") } - archiveName = "allopen-compiler-plugin.jar" } dist { from(jar) + rename("^kotlin-", "") } ideaPlugin { from(jar) + rename("^kotlin-", "") } diff --git a/plugins/allopen/allopen-ide/build.gradle.kts b/plugins/allopen/allopen-ide/build.gradle.kts index 4507e21a635..8feea1447f8 100644 --- a/plugins/allopen/allopen-ide/build.gradle.kts +++ b/plugins/allopen/allopen-ide/build.gradle.kts @@ -4,7 +4,7 @@ apply { plugin("kotlin") } dependencies { val compile by configurations - compile(project(":plugins:allopen-cli")) + compile(project(":kotlin-allopen-compiler-plugin")) compile(project(":compiler:util")) compile(project(":compiler:frontend")) compile(project(":compiler:cli-common")) diff --git a/plugins/noarg/noarg-cli/build.gradle.kts b/plugins/noarg/noarg-cli/build.gradle.kts index c64acc9f42a..ffcdbc4bf8e 100644 --- a/plugins/noarg/noarg-cli/build.gradle.kts +++ b/plugins/noarg/noarg-cli/build.gradle.kts @@ -1,32 +1,34 @@ -import org.gradle.jvm.tasks.Jar +description = "Kotlin NoArg Compiler Plugin" apply { plugin("kotlin") } dependencies { - val compile by configurations - compile(project(":compiler:frontend")) - compile(project(":compiler:frontend.java")) - compile(project(":compiler:backend")) - compile(project(":compiler:util")) - compile(project(":compiler:plugin-api")) + val compileOnly by configurations + val runtime by configurations + compileOnly(project(":compiler:frontend")) + compileOnly(project(":compiler:frontend.java")) + compileOnly(project(":compiler:backend")) + compileOnly(project(":compiler:util")) + compileOnly(project(":compiler:plugin-api")) + runtime(project(":kotlin-compiler", configuration = "runtimeJar")) + runtime(project(":kotlin-stdlib")) } configureKotlinProjectSourcesDefault() configureKotlinProjectNoTests() -val jar: Jar by tasks -jar.apply { - setupRuntimeJar("Kotlin NoArg Compiler Plugin") +val jar = runtimeJar { from(fileTree("$projectDir/src")) { include("META-INF/**") } - archiveName = "noarg-compiler-plugin.jar" } dist { from(jar) + rename("^kotlin-", "") } ideaPlugin { from(jar) + rename("^kotlin-", "") } diff --git a/plugins/noarg/noarg-ide/build.gradle.kts b/plugins/noarg/noarg-ide/build.gradle.kts index 6b803dfbf86..9c0ad526cd7 100644 --- a/plugins/noarg/noarg-ide/build.gradle.kts +++ b/plugins/noarg/noarg-ide/build.gradle.kts @@ -5,7 +5,7 @@ apply { plugin("kotlin") } dependencies { val compile by configurations - compile(project(":plugins:noarg-cli")) + compile(project(":kotlin-noarg-compiler-plugin")) compile(project(":compiler:util")) compile(project(":compiler:frontend")) compile(project(":compiler:frontend.java")) diff --git a/plugins/plugins-tests/build.gradle.kts b/plugins/plugins-tests/build.gradle.kts index 1bfb97ecfe9..cbf3d3b51fe 100644 --- a/plugins/plugins-tests/build.gradle.kts +++ b/plugins/plugins-tests/build.gradle.kts @@ -14,12 +14,12 @@ dependencies { testCompile(project(":plugins:android-extensions-compiler")) testCompile(project(":plugins:android-extensions-idea")) testCompile(project(":plugins:allopen-ide")) { isTransitive = false } - testCompile(project(":plugins:allopen-cli")) + testCompile(project(":kotlin-allopen-compiler-plugin")) testCompile(project(":plugins:noarg-ide")) { isTransitive = false } - testCompile(project(":plugins:noarg-cli")) + testCompile(project(":kotlin-noarg-compiler-plugin")) testCompile(project(":plugins:annotation-based-compiler-plugins-ide-support")) { isTransitive = false } testCompile(project(":plugins:sam-with-receiver-ide")) { isTransitive = false } - testCompile(project(":plugins:sam-with-receiver-cli")) + testCompile(project(":kotlin-sam-with-receiver-compiler-plugin")) testCompile(project(":idea:idea-android")) { isTransitive = false } testCompile(project(":plugins:lint")) { isTransitive = false } testCompile(project(":plugins:uast-kotlin")) diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts b/plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts index 3f1223c4ad3..1abaa8de4ec 100644 --- a/plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts +++ b/plugins/sam-with-receiver/sam-with-receiver-cli/build.gradle.kts @@ -1,30 +1,36 @@ -import org.gradle.jvm.tasks.Jar +description = "Kotlin SamWithReceiver Compiler Plugin" apply { plugin("kotlin") } dependencies { - val compile by configurations - compile(project(":compiler:frontend")) - compile(project(":compiler:frontend.java")) - compile(project(":compiler:plugin-api")) + val compileOnly by configurations + val runtime by configurations + compileOnly(project(":compiler:frontend")) + compileOnly(project(":compiler:frontend.java")) + compileOnly(project(":compiler:plugin-api")) + runtime(project(":kotlin-compiler", configuration = "runtimeJar")) + runtime(project(":kotlin-stdlib")) } configureKotlinProjectSourcesDefault() configureKotlinProjectNoTests() -val jar: Jar by tasks -jar.apply { - setupRuntimeJar("Kotlin SamWithReceiver Compiler Plugin") +val jar = runtimeJar { from(fileTree("$projectDir/src")) { include("META-INF/**") } - archiveName = "sam-with-receiver-compiler-plugin.jar" } +sourcesJar() +javadocJar() + +publish() dist { from(jar) + rename("^kotlin-", "") } ideaPlugin { from(jar) + rename("^kotlin-", "") } diff --git a/plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts b/plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts index 8f0f87bed35..cc0194521e2 100644 --- a/plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts +++ b/plugins/sam-with-receiver/sam-with-receiver-ide/build.gradle.kts @@ -4,7 +4,7 @@ apply { plugin("kotlin") } dependencies { val compile by configurations - compile(project(":plugins:sam-with-receiver-cli")) + compile(project(":kotlin-sam-with-receiver-compiler-plugin")) compile(project(":plugins:annotation-based-compiler-plugins-ide-support")) compile(project(":compiler:util")) compile(project(":compiler:frontend")) diff --git a/plugins/source-sections/source-sections-compiler/build.gradle.kts b/plugins/source-sections/source-sections-compiler/build.gradle.kts index 98454073034..c5ce57937f2 100644 --- a/plugins/source-sections/source-sections-compiler/build.gradle.kts +++ b/plugins/source-sections/source-sections-compiler/build.gradle.kts @@ -1,5 +1,5 @@ -import org.gradle.jvm.tasks.Jar +description = "Kotlin SourceSections Compiler Plugin" apply { plugin("kotlin") } @@ -9,9 +9,12 @@ dependencies { val testCompile by configurations val testCompileOnly by configurations val testRuntime by configurations - compile(project(":compiler:frontend")) - compile(project(":compiler:frontend.script")) - compile(project(":compiler:plugin-api")) + compileOnly(project(":compiler:frontend")) + compileOnly(project(":compiler:frontend.script")) + compileOnly(project(":compiler:plugin-api")) + testCompile(project(":compiler:frontend")) + testCompile(project(":compiler:frontend.script")) + testCompile(project(":compiler:plugin-api")) testCompile(project(":compiler.tests-common")) testCompile(commonDep("junit:junit")) testCompile(project(":compiler:util")) @@ -28,11 +31,11 @@ configureKotlinProjectResources("src") { } configureKotlinProjectTestsDefault() -val jar: Jar by tasks -jar.apply { - setupRuntimeJar("Kotlin SourceSections Compiler Plugin") - archiveName = "kotlin-source-sections-compiler-plugin.jar" -} +val jar = runtimeJar() +sourcesJar() +javadocJar() + +publish() dist { from(jar) diff --git a/prepare/compiler-client-embeddable/build.gradle.kts b/prepare/compiler-client-embeddable/build.gradle.kts index 9f46522898a..000cf07ecaf 100644 --- a/prepare/compiler-client-embeddable/build.gradle.kts +++ b/prepare/compiler-client-embeddable/build.gradle.kts @@ -1,38 +1,7 @@ -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +description = "Kotlin compiler client embeddable" + buildscript { repositories { jcenter() @@ -53,7 +22,6 @@ val jarContents by configurations.creating val testRuntimeCompilerJar by configurations.creating val testStdlibJar by configurations.creating val testScriptRuntimeJar by configurations.creating -val default by configurations val archives by configurations val projectsToInclude = listOf( @@ -70,18 +38,11 @@ dependencies { testCompile(commonDep("junit:junit")) testCompile(project(":kotlin-test:kotlin-test-jvm")) testCompile(project(":kotlin-test:kotlin-test-junit")) - testRuntimeCompilerJar(project(":compiler", configuration = "compilerJar")) + testRuntimeCompilerJar(project(":kotlin-compiler", configuration = "runtimeJar")) testStdlibJar(project(":kotlin-stdlib", configuration = "mainJar")) testScriptRuntimeJar(project(":kotlin-script-runtime", configuration = "mainJar")) } -val shadowJar by task { - setupRuntimeJar("Kotlin compiler client embeddable") - baseName = "kotlin-compiler-client-embeddable" - from(jarContents) - classifier = "" -} - configureKotlinProjectSources() // no sources configureKotlinProjectTests("libraries/tools/kotlin-compiler-client-embeddable-test/src", sourcesBaseDir = rootDir) @@ -108,18 +69,15 @@ archives.artifacts.let { artifacts -> } } -artifacts.add(default.name, shadowJar.outputs.files.singleFile) { - builtBy(shadowJar) - classifier = "" -} - -artifacts.add("archives", shadowJar.outputs.files.singleFile) { - builtBy(shadowJar) - classifier = "" +runtimeJar(task("shadowJar")) { + from(jarContents) } +sourcesJar() +javadocJar() -apply() +publish() +// TODO: remove after finalizing publishing (now due to the problems with sam-with-receiver, the code is not fully navigable in the buildSrc) //tasks { // "uploadArchives"(Upload::class) { // diff --git a/prepare/compiler-embeddable/build.gradle.kts b/prepare/compiler-embeddable/build.gradle.kts index 3bb8417620a..0e3246d40b3 100644 --- a/prepare/compiler-embeddable/build.gradle.kts +++ b/prepare/compiler-embeddable/build.gradle.kts @@ -1,6 +1,8 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +description = "Kotlin Compiler (embeddable)" + buildscript { repositories { jcenter() @@ -11,10 +13,7 @@ buildscript { } } -val embedCfg = configurations.create("embed") -val mainCfg = configurations.create("default") - -val embeddableCompilerBaseName: String by rootProject.extra +val compilerJar by configurations.creating val kotlinEmbeddableRootPackage = "org.jetbrains.kotlin" @@ -31,16 +30,14 @@ val packagesToRelocate = "org.fusesource") dependencies { - embedCfg(project(":prepare:compiler", configuration = "default")) + compilerJar(project(":kotlin-compiler", configuration = "runtimeJar")) } -val embeddableTask = task("prepare") { +runtimeJar(task("embeddable")) { destinationDir = File(buildDir, "libs") - baseName = embeddableCompilerBaseName - configurations = listOf(mainCfg) duplicatesStrategy = DuplicatesStrategy.EXCLUDE - dependsOn(":build-common:assemble", ":core:script.runtime:assemble") - from(embedCfg.files) +// dependsOn(":kotlin-compiler:proguard") + from(compilerJar) relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf") packagesToRelocate.forEach { relocate(it, "$kotlinEmbeddableRootPackage.$it") @@ -51,9 +48,8 @@ val embeddableTask = task("prepare") { } } -defaultTasks(embeddableTask.name) +sourcesJar() +javadocJar() + +publish() -artifacts.add(mainCfg.name, embeddableTask.outputs.files.singleFile) { - builtBy(embeddableTask) - classifier = "" -} diff --git a/prepare/compiler/build.gradle.kts b/prepare/compiler/build.gradle.kts index d7bf20fa889..46322cf5af3 100644 --- a/prepare/compiler/build.gradle.kts +++ b/prepare/compiler/build.gradle.kts @@ -4,6 +4,8 @@ import proguard.gradle.ProGuardTask import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.api.file.DuplicatesStrategy +description = "Kotlin Compiler" + buildscript { repositories { jcenter() @@ -15,22 +17,21 @@ buildscript { } } -apply { plugin("maven") } +plugins { + `java-base` +} // Set to false to disable proguard run on kotlin-compiler.jar. Speeds up the build val shrink = true -val bootstrapBuild = false - val compilerManifestClassPath = - if (bootstrapBuild) "kotlin-runtime-internal-bootstrap.jar kotlin-reflect-internal-bootstrap.jar kotlin-script-runtime-internal-bootstrap.jar" - else "kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar" + "kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar" -val ideaSdkCoreCfg = configurations.create("ideaSdk-core") -val otherDepsCfg = configurations.create("other-deps") -val proguardLibraryJarsCfg = configurations.create("library-jars") -val mainCfg = configurations.create("default_") -val packedCfg = configurations.create("packed") -//val withBootstrapRuntimeCfg = configurations.create("withBootstrapRuntime") +val fatJarContents by configurations.creating +val fatSourcesJarContents by configurations.creating +val proguardLibraryJars by configurations.creating +val fatJar by configurations.creating +val compilerJar by configurations.creating +val archives by configurations val compilerBaseName: String by rootProject.extra @@ -38,81 +39,113 @@ val outputJar = File(buildDir, "libs", "$compilerBaseName.jar") val javaHome = System.getProperty("java.home") -val compilerProject = project(":compiler") +val compilerModules: Array by rootProject.extra + +val packagesToRelocate = + listOf("com.intellij", + "com.google", + "com.sampullara", + "org.apache", + "org.jdom", + "org.picocontainer", + "jline", + "gnu", + "javax.inject", + "org.fusesource") + +fun firstFromJavaHomeThatExists(vararg paths: String): File = + paths.mapNotNull { File(javaHome, it).takeIf { it.exists() } }.firstOrNull() + ?: throw GradleException("Cannot find under '$javaHome' neither of: ${paths.joinToString()}") + +compilerModules.forEach { evaluationDependsOn(it) } + +val compiledModulesSources = compilerModules.map { + project(it).the().sourceSets.getByName("main").allSource +} dependencies { - ideaSdkCoreCfg(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) - ideaSdkCoreCfg(ideaSdkDeps("jna-platform", "oromatcher")) - ideaSdkCoreCfg(ideaSdkDeps("jps-model.jar", subdir = "jps")) - otherDepsCfg(commonDep("javax.inject")) - otherDepsCfg(commonDep("org.jline", "jline")) - otherDepsCfg(protobufFull()) - otherDepsCfg(commonDep("com.github.spullara.cli-parser", "cli-parser")) - otherDepsCfg(commonDep("com.google.code.findbugs", "jsr305")) - otherDepsCfg(commonDep("io.javaslang","javaslang")) - otherDepsCfg(preloadedDeps("json-org")) - buildVersion() - proguardLibraryJarsCfg(files("$javaHome/lib/rt.jar".takeIf { File(it).exists() } ?: "$javaHome/../Classes/classes.jar", - "$javaHome/lib/jsse.jar".takeIf { File(it).exists() } ?: "$javaHome/../Classes/jsse.jar")) - proguardLibraryJarsCfg(kotlinDep("stdlib")) - proguardLibraryJarsCfg(kotlinDep("script-runtime")) - proguardLibraryJarsCfg(kotlinDep("reflect")) - proguardLibraryJarsCfg(files("${System.getProperty("java.home")}/../lib/tools.jar")) -// proguardLibraryJarsCfg(project(":prepare:runtime", configuration = "default").apply { isTransitive = false }) -// proguardLibraryJarsCfg(project(":prepare:reflect", configuration = "default").apply { isTransitive = false }) -// proguardLibraryJarsCfg(project(":core:script.runtime").apply { isTransitive = false }) + compilerModules.forEach { + fatJarContents(project(it)) { isTransitive = false } + } + compiledModulesSources.forEach { + fatSourcesJarContents(it) + } +// buildVersion() + + fatJarContents(project(":core:builtins", configuration = "builtins")) + fatJarContents(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array))) + fatJarContents(ideaSdkDeps("jna-platform", "oromatcher")) + fatJarContents(ideaSdkDeps("jps-model.jar", subdir = "jps")) + fatJarContents(commonDep("javax.inject")) + fatJarContents(commonDep("org.jline", "jline")) + fatJarContents(protobufFull()) + fatJarContents(commonDep("com.github.spullara.cli-parser", "cli-parser")) + fatJarContents(commonDep("com.google.code.findbugs", "jsr305")) + fatJarContents(commonDep("io.javaslang", "javaslang")) + fatJarContents(preloadedDeps("json-org")) + + proguardLibraryJars(files(firstFromJavaHomeThatExists("lib/rt.jar", "../Classes/classes.jar"), + firstFromJavaHomeThatExists("lib/jsse.jar", "../Classes/jsse.jar"), + firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar"))) + proguardLibraryJars(project(":kotlin-stdlib", configuration = "mainJar")) + proguardLibraryJars(project(":kotlin-script-runtime", configuration = "mainJar")) + proguardLibraryJars(project(":kotlin-reflect", configuration = "mainJar")) + proguardLibraryJars(preloadedDeps("kotlinx-coroutines-core")) + +// proguardLibraryJars(project(":prepare:runtime", configuration = "default").apply { isTransitive = false }) +// proguardLibraryJars(project(":prepare:reflect", configuration = "default").apply { isTransitive = false }) +// proguardLibraryJars(project(":core:script.runtime").apply { isTransitive = false }) } -val packCompilerTask = task("internal.pack-compiler") { - configurations = listOf(packedCfg) +val packCompiler by task { + configurations = listOf(fatJar) duplicatesStrategy = DuplicatesStrategy.EXCLUDE destinationDir = File(buildDir, "libs") - baseName = compilerBaseName + "-before-shrink" +// baseName = compilerBaseName dependsOn(protobufFullTask) - setupRuntimeJar("Kotlin Compiler") - (rootProject.extra["compilerModules"] as Array).forEach { - dependsOn("$it:classes") - from(project(it).getCompiledClasses()) - } - from(ideaSdkCoreCfg.files) - from(otherDepsCfg.files) - from(project(":core:builtins").getResourceFiles()) { include("kotlin/**") } + + setupPublicJar("before-proguard", "") + from(fatJarContents) manifest.attributes.put("Class-Path", compilerManifestClassPath) manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") } -val proguardTask = task("internal.proguard-compiler") { - dependsOn(packCompilerTask) +val proguard by task { + dependsOn(packCompiler) configuration("$rootDir/compiler/compiler.pro") - inputs.files(packCompilerTask.outputs.files.singleFile) + val outputJar = File(buildDir, "libs", "$compilerBaseName-after-proguard.jar") + + inputs.files(packCompiler.outputs.files.singleFile) outputs.file(outputJar) // TODO: remove after dropping compatibility with ant build doFirst { - System.setProperty("kotlin-compiler-jar-before-shrink", packCompilerTask.outputs.files.singleFile.canonicalPath) + System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.outputs.files.singleFile.canonicalPath) System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath) } - proguardLibraryJarsCfg.files.forEach { jar -> - libraryjars(jar) - } + libraryjars(proguardLibraryJars) printconfiguration("$buildDir/compiler.pro.dump") } dist { if (shrink) { - from(proguardTask) + from(proguard) } else { - from(packCompilerTask) - rename("-before-shrink", "") + from(packCompiler) } + rename(".*", compilerBaseName + ".jar") } -artifacts.add(mainCfg.name, proguardTask.outputs.files.singleFile) { - builtBy(proguardTask) +runtimeJarArtifactBy(proguard, proguard.outputs.files.singleFile) { + name = compilerBaseName classifier = "" } +sourcesJar { + from(fatSourcesJarContents) +} +javadocJar() - +publish() diff --git a/prepare/daemon-client/build.gradle.kts b/prepare/daemon-client/build.gradle.kts new file mode 100644 index 00000000000..154cf5bc0c5 --- /dev/null +++ b/prepare/daemon-client/build.gradle.kts @@ -0,0 +1,31 @@ + +description = "Kotlin Daemon Client" + +apply { plugin("kotlin") } + +val nativePlatformUberjar = "$rootDir/dependencies/native-platform-uberjar.jar" + +dependencies { + val compile by configurations + compile(project(":compiler:util")) + compile(project(":compiler:cli-common")) + compile(project(":compiler:daemon-common")) + compile(files(nativePlatformUberjar)) + buildVersion() +} + +configureKotlinProjectSourcesDefault() +configureKotlinProjectNoTests() + +val jar = runtimeJar { + from(zipTree(nativePlatformUberjar)) +} + +sourcesJar() +javadocJar() + +dist { + from(jar) +} + +publish() diff --git a/settings.gradle b/settings.gradle index b5299cdf8bc..7bc9cc15137 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,8 +4,8 @@ include ":build-common", ":compiler", ":compiler:util", ":compiler:daemon-common", - ":compiler:daemon-client", - ":compiler:preloader", + ":kotlin-daemon-client", + ":kotlin-preloader", ":compiler:cli-runner", ":compiler:container", ":compiler:resolution", @@ -55,13 +55,13 @@ include ":build-common", ":plugins:android-extensions-compiler", ":plugins:android-extensions-idea", ":plugins:android-extensions-jps", - ":plugins:allopen-cli", + ":kotlin-allopen-compiler-plugin", ":plugins:allopen-ide", - ":plugins:noarg-cli", + ":kotlin-noarg-compiler-plugin", ":plugins:noarg-ide", - ":plugins:sam-with-receiver-cli", + ":kotlin-sam-with-receiver-compiler-plugin", ":plugins:sam-with-receiver-ide", - ":plugins:source-sections-compiler", + ":kotlin-source-sections-compiler-plugin", ":plugins:uast-kotlin", ":plugins:uast-kotlin-idea", ":plugins:annotation-based-compiler-plugins-ide-support", @@ -86,7 +86,10 @@ include ":build-common", ":prepare:kotlin-plugin", ":prepare:android-lint", ":prepare:mock-runtime-for-test", - ":prepare:compiler-client-embeddable", + ":kotlin-compiler", + ":kotlin-compiler-embeddable", + ":kotlin-compiler-client-embeddable", + ":kotlin-daemon-client", ":kotlin-reflect", ":ant", ":compiler:tests-java8", @@ -119,10 +122,14 @@ project(':kotlin-stdlib-jre7').projectDir = "$rootDir/libraries/stdlib/jre7" as project(':kotlin-stdlib-jre8').projectDir = "$rootDir/libraries/stdlib/jre8" as File project(':kotlin-stdlib:samples').projectDir = "$rootDir/libraries/stdlib/samples" as File project(':kotlin-reflect').projectDir = "$rootDir/libraries/tools/kotlin-reflect" as File +project(':kotlin-compiler').projectDir = "$rootDir/prepare/compiler" as File +project(':kotlin-compiler-embeddable').projectDir = "$rootDir/prepare/compiler-embeddable" as File +project(':kotlin-compiler-client-embeddable').projectDir = "$rootDir/prepare/compiler-client-embeddable" as File +project(':kotlin-daemon-client').projectDir = "$rootDir/prepare/daemon-client" as File project(':compiler:cli-common').projectDir = "$rootDir/compiler/cli/cli-common" as File project(':compiler:cli-runner').projectDir = "$rootDir/compiler/cli/cli-runner" as File project(':compiler:daemon-common').projectDir = "$rootDir/compiler/daemon/daemon-common" as File -project(':compiler:daemon-client').projectDir = "$rootDir/compiler/daemon/daemon-client" as File +project(':kotlin-daemon-client').projectDir = "$rootDir/compiler/daemon/daemon-client" as File project(':compiler:ir.tree').projectDir = "$rootDir/compiler/ir/ir.tree" as File project(':compiler:ir.psi2ir').projectDir = "$rootDir/compiler/ir/ir.psi2ir" as File project(':compiler:ir.ir2cfg').projectDir = "$rootDir/compiler/ir/ir.ir2cfg" as File @@ -130,13 +137,13 @@ project(':idea:idea-android-output-parser').projectDir = "$rootDir/idea/idea-and project(':plugins:android-extensions-compiler').projectDir = "$rootDir/plugins/android-extensions/android-extensions-compiler" as File project(':plugins:android-extensions-idea').projectDir = "$rootDir/plugins/android-extensions/android-extensions-idea" as File project(':plugins:android-extensions-jps').projectDir = "$rootDir/plugins/android-extensions/android-extensions-jps" as File -project(':plugins:allopen-cli').projectDir = "$rootDir/plugins/allopen/allopen-cli" as File +project(':kotlin-allopen-compiler-plugin').projectDir = "$rootDir/plugins/allopen/allopen-cli" as File project(':plugins:allopen-ide').projectDir = "$rootDir/plugins/allopen/allopen-ide" as File -project(':plugins:noarg-cli').projectDir = "$rootDir/plugins/noarg/noarg-cli" as File +project(':kotlin-noarg-compiler-plugin').projectDir = "$rootDir/plugins/noarg/noarg-cli" as File project(':plugins:noarg-ide').projectDir = "$rootDir/plugins/noarg/noarg-ide" as File -project(':plugins:sam-with-receiver-cli').projectDir = "$rootDir/plugins/sam-with-receiver/sam-with-receiver-cli" as File +project(':kotlin-sam-with-receiver-compiler-plugin').projectDir = "$rootDir/plugins/sam-with-receiver/sam-with-receiver-cli" as File project(':plugins:sam-with-receiver-ide').projectDir = "$rootDir/plugins/sam-with-receiver/sam-with-receiver-ide" as File -project(':plugins:source-sections-compiler').projectDir = "$rootDir/plugins/source-sections/source-sections-compiler" as File +project(':kotlin-source-sections-compiler-plugin').projectDir = "$rootDir/plugins/source-sections/source-sections-compiler" as File project(':tools:binary-compatibility-validator').projectDir = "$rootDir/libraries/tools/binary-compatibility-validator" as File project(':tools:kotlin-stdlib-js-merger').projectDir = "$rootDir/libraries/tools/kotlin-stdlib-js-merger" as File project(':tools:kotlin-stdlib-gen').projectDir = "$rootDir/libraries/tools/kotlin-stdlib-gen" as File -- GitLab