Refactor :kotlin-compiler project to allow project(":kotlin-compiler") dependencies

This commit is contained in:
Vyacheslav Gerasimov
2018-08-22 03:08:40 +03:00
parent 023b1b1880
commit 053a4b714c
4 changed files with 139 additions and 91 deletions
+7 -4
View File
@@ -72,7 +72,7 @@ fun<T: Jar> 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<BasePluginConvention>().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<BasePluginConvention>().archivesBaseName)
put("Implementation-Version", project.rootProject.extra["buildNumber"])
put("Implementation-Title", baseName)
put("Implementation-Version", buildNumber)
put("Build-Jdk", System.getProperty("java.version"))
}
}
+44 -29
View File
@@ -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<MavenPluginConvention>()
.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<ShadowJar> {
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<ProGuardTask> {
@@ -108,25 +120,28 @@ val proguard by task<ProGuardTask> {
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()
+44 -29
View File
@@ -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<MavenPluginConvention>()
.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<ShadowJar> {
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<ProGuardTask> {
@@ -108,25 +120,28 @@ val proguard by task<ProGuardTask> {
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()
+44 -29
View File
@@ -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<MavenPluginConvention>()
.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<ShadowJar> {
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<ProGuardTask> {
@@ -108,25 +120,28 @@ val proguard by task<ProGuardTask> {
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()