From 053a4b714cbcf2eaa07b4f26caf6a6887c4a8af2 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Wed, 22 Aug 2018 03:08:40 +0300 Subject: [PATCH] Refactor :kotlin-compiler project to allow project(":kotlin-compiler") dependencies --- buildSrc/src/main/kotlin/artifacts.kt | 11 ++-- prepare/compiler/build.gradle.kts | 73 ++++++++++++++++----------- prepare/compiler/build.gradle.kts.173 | 73 ++++++++++++++++----------- prepare/compiler/build.gradle.kts.181 | 73 ++++++++++++++++----------- 4 files changed, 139 insertions(+), 91 deletions(-) diff --git a/buildSrc/src/main/kotlin/artifacts.kt b/buildSrc/src/main/kotlin/artifacts.kt index c17743055a6..f9ca6bb2ef3 100644 --- a/buildSrc/src/main/kotlin/artifacts.kt +++ b/buildSrc/src/main/kotlin/artifacts.kt @@ -72,7 +72,7 @@ fun Project.runtimeJar(task: T, body: T.() -> Unit = {}): T { configurations.getOrCreate("archives").artifacts.removeAll { (it as? ArchivePublishArtifact)?.archiveTask?.let { it == defaultJarTask } ?: false } } return task.apply { - setupPublicJar() + setupPublicJar(project.the().archivesBaseName) duplicatesStrategy = DuplicatesStrategy.EXCLUDE body() project.runtimeJarArtifactBy(this, this) @@ -181,12 +181,15 @@ private fun Project.runtimeJarTaskIfExists(): Task? = fun ConfigurationContainer.getOrCreate(name: String): Configuration = findByName(name) ?: create(name) -fun Jar.setupPublicJar(classifier: String = "") { +fun Jar.setupPublicJar(baseName: String, classifier: String = "") { + val buildNumber = project.rootProject.extra["buildNumber"] as String + this.baseName = baseName + this.version = buildNumber this.classifier = classifier manifest.attributes.apply { put("Implementation-Vendor", "JetBrains") - put("Implementation-Title", project.the().archivesBaseName) - put("Implementation-Version", project.rootProject.extra["buildNumber"]) + put("Implementation-Title", baseName) + put("Implementation-Version", buildNumber) put("Build-Jdk", System.getProperty("java.version")) } } diff --git a/prepare/compiler/build.gradle.kts b/prepare/compiler/build.gradle.kts index a1b7047e056..e1f9bd325db 100644 --- a/prepare/compiler/build.gradle.kts +++ b/prepare/compiler/build.gradle.kts @@ -1,32 +1,40 @@ import java.io.File import proguard.gradle.ProGuardTask import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.artifacts.maven.Conf2ScopeMappingContainer.COMPILE import org.gradle.api.file.DuplicatesStrategy description = "Kotlin Compiler" plugins { - `java` + maven } // You can run Gradle with "-Pkotlin.build.proguard=true" to enable ProGuard run on kotlin-compiler.jar (on TeamCity, ProGuard always runs) val shrink = - findProperty("kotlin.build.proguard")?.toString()?.toBoolean() - ?: hasProperty("teamcity") + findProperty("kotlin.build.proguard")?.toString()?.toBoolean() + ?: hasProperty("teamcity") -val compilerManifestClassPath = - "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar" +val compilerManifestClassPath = "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar" val fatJarContents by configurations.creating val fatJarContentsStripMetadata by configurations.creating val fatJarContentsStripServices 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 compile by configurations +val runtimeJar by configurations.creating +val libraries by configurations.creating + +val compile by configurations.creating { + the() + .conf2ScopeMappings + .addMapping(0, this, COMPILE) +} + +val default by configurations +default.extendsFrom(runtimeJar) val compilerBaseName = name @@ -41,9 +49,24 @@ val compiledModulesSources = compilerModules.map { } dependencies { + // Maven plugin generates pom compile dependencies from compile configuration + compile(project(":kotlin-stdlib")) + compile(project(":kotlin-script-runtime")) + compile(project(":kotlin-reflect")) + + libraries(project(":kotlin-annotations-jvm")) + libraries( + files( + firstFromJavaHomeThatExists("jre/lib/rt.jar", "../Classes/classes.jar"), + firstFromJavaHomeThatExists("jre/lib/jsse.jar", "../Classes/jsse.jar"), + toolsJar() + ) + ) + compilerModules.forEach { fatJarContents(project(it)) { isTransitive = false } } + compiledModulesSources.forEach { fatSourcesJarContents(it) } @@ -57,18 +80,6 @@ dependencies { fatJarContents(commonDep("io.javaslang", "javaslang")) fatJarContents(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } - proguardLibraryJars(files(firstFromJavaHomeThatExists("jre/lib/rt.jar", "../Classes/classes.jar"), - firstFromJavaHomeThatExists("jre/lib/jsse.jar", "../Classes/jsse.jar"), - toolsJar())) - proguardLibraryJars(projectDist(":kotlin-stdlib")) - proguardLibraryJars(projectDist(":kotlin-script-runtime")) - proguardLibraryJars(projectDist(":kotlin-reflect")) - proguardLibraryJars(project(":kotlin-annotations-jvm")) - proguardLibraryJars(projectDist(":kotlin-scripting-common")) - - compile(project(":kotlin-stdlib")) - compile(project(":kotlin-script-runtime")) - compile(project(":kotlin-reflect")) fatJarContents(intellijCoreDep()) { includeJars("intellij-core") } fatJarContents(intellijDep()) { includeIntellijCoreJarDependencies(project, { !(it.startsWith("jdom") || it.startsWith("log4j")) }) } fatJarContents(intellijDep()) { includeJars("jna-platform", "lz4-1.3.0") } @@ -82,15 +93,16 @@ val packCompiler by task { duplicatesStrategy = DuplicatesStrategy.EXCLUDE destinationDir = File(buildDir, "libs") - setupPublicJar("before-proguard") + setupPublicJar(compilerBaseName, "before-proguard") + from(fatJarContents) afterEvaluate { fatJarContentsStripServices.files.forEach { from(zipTree(it)) { exclude("META-INF/services/**") } } fatJarContentsStripMetadata.files.forEach { from(zipTree(it)) { exclude("META-INF/jb/** META-INF/LICENSE") } } } - manifest.attributes.put("Class-Path", compilerManifestClassPath) - manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") + manifest.attributes["Class-Path"] = compilerManifestClassPath + manifest.attributes["Main-Class"] = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" } val proguard by task { @@ -108,25 +120,28 @@ val proguard by task { System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath) } - libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraryJars) + libraryjars(mapOf("filter" to "!META-INF/versions/**"), compile) + libraryjars(mapOf("filter" to "!META-INF/versions/**"), libraries) + printconfiguration("$buildDir/compiler.pro.dump") } -noDefaultJar() - val pack = if (shrink) proguard else packCompiler -dist(targetName = compilerBaseName + ".jar", - fromTask = pack) +dist( + targetName = "$compilerBaseName.jar", + fromTask = pack +) runtimeJarArtifactBy(pack, pack.outputs.files.singleFile) { name = compilerBaseName classifier = "" } + sourcesJar { from(fatSourcesJarContents) } + javadocJar() publish() - diff --git a/prepare/compiler/build.gradle.kts.173 b/prepare/compiler/build.gradle.kts.173 index b3f4f2e85c5..0ed65d91f16 100644 --- a/prepare/compiler/build.gradle.kts.173 +++ b/prepare/compiler/build.gradle.kts.173 @@ -1,32 +1,40 @@ import java.io.File import proguard.gradle.ProGuardTask import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.artifacts.maven.Conf2ScopeMappingContainer.COMPILE import org.gradle.api.file.DuplicatesStrategy description = "Kotlin Compiler" plugins { - `java` + maven } // You can run Gradle with "-Pkotlin.build.proguard=true" to enable ProGuard run on kotlin-compiler.jar (on TeamCity, ProGuard always runs) val shrink = - findProperty("kotlin.build.proguard")?.toString()?.toBoolean() - ?: hasProperty("teamcity") + findProperty("kotlin.build.proguard")?.toString()?.toBoolean() + ?: hasProperty("teamcity") -val compilerManifestClassPath = - "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar" +val compilerManifestClassPath = "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar" val fatJarContents by configurations.creating val fatJarContentsStripMetadata by configurations.creating val fatJarContentsStripServices 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 compile by configurations +val runtimeJar by configurations.creating +val libraries by configurations.creating + +val compile by configurations.creating { + the() + .conf2ScopeMappings + .addMapping(0, this, COMPILE) +} + +val default by configurations +default.extendsFrom(runtimeJar) val compilerBaseName = name @@ -41,9 +49,24 @@ val compiledModulesSources = compilerModules.map { } dependencies { + // Maven plugin generates pom compile dependencies from compile configuration + compile(project(":kotlin-stdlib")) + compile(project(":kotlin-script-runtime")) + compile(project(":kotlin-reflect")) + + libraries(project(":kotlin-annotations-jvm")) + libraries( + files( + firstFromJavaHomeThatExists("jre/lib/rt.jar", "../Classes/classes.jar"), + firstFromJavaHomeThatExists("jre/lib/jsse.jar", "../Classes/jsse.jar"), + toolsJar() + ) + ) + compilerModules.forEach { fatJarContents(project(it)) { isTransitive = false } } + compiledModulesSources.forEach { fatSourcesJarContents(it) } @@ -57,18 +80,6 @@ dependencies { fatJarContents(commonDep("io.javaslang", "javaslang")) fatJarContents(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } - proguardLibraryJars(files(firstFromJavaHomeThatExists("jre/lib/rt.jar", "../Classes/classes.jar"), - firstFromJavaHomeThatExists("jre/lib/jsse.jar", "../Classes/jsse.jar"), - toolsJar())) - proguardLibraryJars(projectDist(":kotlin-stdlib")) - proguardLibraryJars(projectDist(":kotlin-script-runtime")) - proguardLibraryJars(projectDist(":kotlin-reflect")) - proguardLibraryJars(project(":kotlin-annotations-jvm")) - proguardLibraryJars(projectDist(":kotlin-scripting-common")) - - compile(project(":kotlin-stdlib")) - compile(project(":kotlin-script-runtime")) - compile(project(":kotlin-reflect")) fatJarContents(intellijCoreDep()) { includeJars("intellij-core") } fatJarContents(intellijDep()) { includeIntellijCoreJarDependencies(project, { !(it.startsWith("jdom") || it.startsWith("log4j")) }) } fatJarContents(intellijDep()) { includeJars("jna-platform") } @@ -82,15 +93,16 @@ val packCompiler by task { duplicatesStrategy = DuplicatesStrategy.EXCLUDE destinationDir = File(buildDir, "libs") - setupPublicJar("before-proguard") + setupPublicJar(compilerBaseName, "before-proguard") + from(fatJarContents) afterEvaluate { fatJarContentsStripServices.files.forEach { from(zipTree(it)) { exclude("META-INF/services/**") } } fatJarContentsStripMetadata.files.forEach { from(zipTree(it)) { exclude("META-INF/jb/** META-INF/LICENSE") } } } - manifest.attributes.put("Class-Path", compilerManifestClassPath) - manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") + manifest.attributes["Class-Path"] = compilerManifestClassPath + manifest.attributes["Main-Class"] = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" } val proguard by task { @@ -108,25 +120,28 @@ val proguard by task { System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath) } - libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraryJars) + libraryjars(mapOf("filter" to "!META-INF/versions/**"), compile) + libraryjars(mapOf("filter" to "!META-INF/versions/**"), libraries) + printconfiguration("$buildDir/compiler.pro.dump") } -noDefaultJar() - val pack = if (shrink) proguard else packCompiler -dist(targetName = compilerBaseName + ".jar", - fromTask = pack) +dist( + targetName = "$compilerBaseName.jar", + fromTask = pack +) runtimeJarArtifactBy(pack, pack.outputs.files.singleFile) { name = compilerBaseName classifier = "" } + sourcesJar { from(fatSourcesJarContents) } + javadocJar() publish() - diff --git a/prepare/compiler/build.gradle.kts.181 b/prepare/compiler/build.gradle.kts.181 index 40d2cc4b9d8..bcd979dae23 100644 --- a/prepare/compiler/build.gradle.kts.181 +++ b/prepare/compiler/build.gradle.kts.181 @@ -1,32 +1,40 @@ import java.io.File import proguard.gradle.ProGuardTask import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.artifacts.maven.Conf2ScopeMappingContainer.COMPILE import org.gradle.api.file.DuplicatesStrategy description = "Kotlin Compiler" plugins { - `java` + maven } // You can run Gradle with "-Pkotlin.build.proguard=true" to enable ProGuard run on kotlin-compiler.jar (on TeamCity, ProGuard always runs) val shrink = - findProperty("kotlin.build.proguard")?.toString()?.toBoolean() - ?: hasProperty("teamcity") + findProperty("kotlin.build.proguard")?.toString()?.toBoolean() + ?: hasProperty("teamcity") -val compilerManifestClassPath = - "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar" +val compilerManifestClassPath = "kotlin-stdlib.jar kotlin-reflect.jar kotlin-script-runtime.jar" val fatJarContents by configurations.creating val fatJarContentsStripMetadata by configurations.creating val fatJarContentsStripServices 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 compile by configurations +val runtimeJar by configurations.creating +val libraries by configurations.creating + +val compile by configurations.creating { + the() + .conf2ScopeMappings + .addMapping(0, this, COMPILE) +} + +val default by configurations +default.extendsFrom(runtimeJar) val compilerBaseName = name @@ -41,9 +49,24 @@ val compiledModulesSources = compilerModules.map { } dependencies { + // Maven plugin generates pom compile dependencies from compile configuration + compile(project(":kotlin-stdlib")) + compile(project(":kotlin-script-runtime")) + compile(project(":kotlin-reflect")) + + libraries(project(":kotlin-annotations-jvm")) + libraries( + files( + firstFromJavaHomeThatExists("jre/lib/rt.jar", "../Classes/classes.jar"), + firstFromJavaHomeThatExists("jre/lib/jsse.jar", "../Classes/jsse.jar"), + toolsJar() + ) + ) + compilerModules.forEach { fatJarContents(project(it)) { isTransitive = false } } + compiledModulesSources.forEach { fatSourcesJarContents(it) } @@ -57,18 +80,6 @@ dependencies { fatJarContents(commonDep("io.javaslang", "javaslang")) fatJarContents(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } - proguardLibraryJars(files(firstFromJavaHomeThatExists("jre/lib/rt.jar", "../Classes/classes.jar"), - firstFromJavaHomeThatExists("jre/lib/jsse.jar", "../Classes/jsse.jar"), - toolsJar())) - proguardLibraryJars(projectDist(":kotlin-stdlib")) - proguardLibraryJars(projectDist(":kotlin-script-runtime")) - proguardLibraryJars(projectDist(":kotlin-reflect")) - proguardLibraryJars(project(":kotlin-annotations-jvm")) - proguardLibraryJars(projectDist(":kotlin-scripting-common")) - - compile(project(":kotlin-stdlib")) - compile(project(":kotlin-script-runtime")) - compile(project(":kotlin-reflect")) fatJarContents(intellijCoreDep()) { includeJars("intellij-core") } fatJarContents(intellijDep()) { includeIntellijCoreJarDependencies(project, { !(it.startsWith("jdom") || it.startsWith("log4j")) }) } fatJarContents(intellijDep()) { includeJars("jna-platform", "lz4-java-1.3") } @@ -82,15 +93,16 @@ val packCompiler by task { duplicatesStrategy = DuplicatesStrategy.EXCLUDE destinationDir = File(buildDir, "libs") - setupPublicJar("before-proguard") + setupPublicJar(compilerBaseName, "before-proguard") + from(fatJarContents) afterEvaluate { fatJarContentsStripServices.files.forEach { from(zipTree(it)) { exclude("META-INF/services/**") } } fatJarContentsStripMetadata.files.forEach { from(zipTree(it)) { exclude("META-INF/jb/** META-INF/LICENSE") } } } - manifest.attributes.put("Class-Path", compilerManifestClassPath) - manifest.attributes.put("Main-Class", "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler") + manifest.attributes["Class-Path"] = compilerManifestClassPath + manifest.attributes["Main-Class"] = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" } val proguard by task { @@ -108,25 +120,28 @@ val proguard by task { System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath) } - libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraryJars) + libraryjars(mapOf("filter" to "!META-INF/versions/**"), compile) + libraryjars(mapOf("filter" to "!META-INF/versions/**"), libraries) + printconfiguration("$buildDir/compiler.pro.dump") } -noDefaultJar() - val pack = if (shrink) proguard else packCompiler -dist(targetName = compilerBaseName + ".jar", - fromTask = pack) +dist( + targetName = "$compilerBaseName.jar", + fromTask = pack +) runtimeJarArtifactBy(pack, pack.outputs.files.singleFile) { name = compilerBaseName classifier = "" } + sourcesJar { from(fatSourcesJarContents) } + javadocJar() publish() -