Move embeddable compiler shading logic to buildSrc, implement rewriteDeps task
the task takes a jar an a shading task (like the one that creates embeddable compiler) and rewrites jar's dependencies to the shaded ones according the the shade task.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
val buildSrcKotlinVersion: String by extra(findProperty("buildSrc.kotlin.version")?.toString() ?: embeddedKotlinVersion)
|
val buildSrcKotlinVersion: String by extra(findProperty("buildSrc.kotlin.version")?.toString() ?: embeddedKotlinVersion)
|
||||||
extra["buildSrcKotlinRepo"] = findProperty("buildSrc.kotlin.repo")
|
extra["buildSrcKotlinRepo"] = findProperty("buildSrc.kotlin.repo")
|
||||||
|
extra["versions.shadow"] = "2.0.1"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
extra["buildSrcKotlinRepo"]?.let {
|
extra["buildSrcKotlinRepo"]?.let {
|
||||||
@@ -34,6 +35,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev") // for dex-method-list
|
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev") // for dex-method-list
|
||||||
// maven { setUrl("https://repo.gradle.org/gradle/libs-releases-local") }
|
// maven { setUrl("https://repo.gradle.org/gradle/libs-releases-local") }
|
||||||
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -42,6 +44,7 @@ dependencies {
|
|||||||
// compile("net.rubygrapefruit:native-platform:0.14")
|
// compile("net.rubygrapefruit:native-platform:0.14")
|
||||||
// TODO: adding the dep to the plugin breaks the build unexpectedly, resolve and uncomment
|
// TODO: adding the dep to the plugin breaks the build unexpectedly, resolve and uncomment
|
||||||
// compile("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["bootstrap_kotlin_version"]}")
|
// compile("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["bootstrap_kotlin_version"]}")
|
||||||
|
compile("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
|
||||||
}
|
}
|
||||||
|
|
||||||
samWithReceiver {
|
samWithReceiver {
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
@file:Suppress("unused") // usages in build scripts are not tracked properly
|
||||||
|
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
import org.gradle.api.GradleException
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.file.DuplicatesStrategy
|
||||||
|
import org.gradle.api.tasks.bundling.Zip
|
||||||
|
import org.gradle.jvm.tasks.Jar
|
||||||
|
import org.gradle.kotlin.dsl.task
|
||||||
|
import org.gradle.kotlin.dsl.*
|
||||||
|
|
||||||
|
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 Project.embeddableCompiler(taskName: String = "embeddable", body: Jar.() -> Unit = {}): Jar {
|
||||||
|
|
||||||
|
val compilerJar = configurations.create("compilerJar")
|
||||||
|
dependencies.add(compilerJar.name, dependencies.project(":kotlin-compiler", configuration = "runtimeJar"))
|
||||||
|
|
||||||
|
return task<ShadowJar>(taskName) {
|
||||||
|
destinationDir = File(buildDir, "libs")
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
from(compilerJar)
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
body()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Project.rewriteDepsToShadedJar(originalJarTask: Jar, shadowJarTask: Zip, body: Jar.() -> Unit = {}): Jar {
|
||||||
|
val originalFiles by lazy {
|
||||||
|
val jarContents = zipTree(originalJarTask.outputs.files.singleFile).files
|
||||||
|
val basePath = jarContents.find { it.name == "MANIFEST.MF" }?.parentFile?.parentFile ?: throw GradleException("cannot determine the jar root dir")
|
||||||
|
jarContents.map { it.relativeTo(basePath).path }.toSet()
|
||||||
|
}
|
||||||
|
return task<Jar>("rewrittenDepsJar") {
|
||||||
|
originalJarTask.apply {
|
||||||
|
classifier = "original"
|
||||||
|
}
|
||||||
|
shadowJarTask.apply {
|
||||||
|
dependsOn(originalJarTask)
|
||||||
|
from(originalJarTask)
|
||||||
|
classifier = "shadow"
|
||||||
|
}
|
||||||
|
dependsOn(shadowJarTask)
|
||||||
|
from(project.zipTree(shadowJarTask.outputs.files.singleFile)) { include { originalFiles.any { originalFile -> it.file.canonicalPath.endsWith(originalFile) } } }
|
||||||
|
body()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Project.rewriteDepsToShadedCompiler(originalJarTask: Jar, body: Jar.() -> Unit = {}): Jar = rewriteDepsToShadedJar(originalJarTask, embeddableCompiler(), body)
|
||||||
@@ -1,44 +1,11 @@
|
|||||||
|
|
||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
|
||||||
|
|
||||||
description = "Kotlin Compiler (embeddable)"
|
description = "Kotlin Compiler (embeddable)"
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
`java`
|
`java`
|
||||||
}
|
}
|
||||||
|
|
||||||
val compilerJar by configurations.creating
|
|
||||||
|
|
||||||
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")
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
val compile by configurations
|
|
||||||
|
|
||||||
compilerJar(projectRuntimeJar(":kotlin-compiler"))
|
|
||||||
|
|
||||||
compile(project(":kotlin-stdlib"))
|
compile(project(":kotlin-stdlib"))
|
||||||
compile(project(":kotlin-script-runtime"))
|
compile(project(":kotlin-script-runtime"))
|
||||||
compile(project(":kotlin-reflect"))
|
compile(project(":kotlin-reflect"))
|
||||||
@@ -46,20 +13,7 @@ dependencies {
|
|||||||
|
|
||||||
noDefaultJar()
|
noDefaultJar()
|
||||||
|
|
||||||
runtimeJar(task<ShadowJar>("embeddable")) {
|
runtimeJar(embeddableCompiler())
|
||||||
destinationDir = File(buildDir, "libs")
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
|
||||||
// dependsOn(":kotlin-compiler:proguard")
|
|
||||||
from(compilerJar)
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourcesJar()
|
sourcesJar()
|
||||||
javadocJar()
|
javadocJar()
|
||||||
|
|||||||
Reference in New Issue
Block a user