Fix dependencies rewriting and gradle integration tests after applying rewriting
This commit is contained in:
@@ -20,26 +20,87 @@ val packagesToRelocate =
|
||||
"org.picocontainer",
|
||||
"jline",
|
||||
"gnu",
|
||||
"javax.inject",
|
||||
"org.fusesource")
|
||||
|
||||
fun Project.embeddableCompiler(taskName: String = "embeddable", body: Jar.() -> Unit = {}): Jar {
|
||||
// The shaded compiler "dummy" is used to rewrite dependencies in projects that are used with the embeddable compiler
|
||||
// on the runtime and use some shaded dependencies from the compiler
|
||||
// To speed-up rewriting process we want to have this dummy as small as possible.
|
||||
// But due to the shadow plugin bug (https://github.com/johnrengelman/shadow/issues/262) it is not possible to use
|
||||
// packagesToRelocate list to for the include list. Therefore the exclude list has to be created.
|
||||
val packagesToExcludeFromDummy =
|
||||
listOf("org/jetbrains/kotlin/**",
|
||||
"org/intellij/lang/annotations/**",
|
||||
"org/jetbrains/jps/**",
|
||||
"META-INF/**",
|
||||
"com/sun/jna/**",
|
||||
"com/thoughtworks/xstream/**",
|
||||
"javaslang/**",
|
||||
"*.proto",
|
||||
"messages/**",
|
||||
"net/sf/cglib/**",
|
||||
"one/util/streamex/**",
|
||||
"org/iq80/snappy/**",
|
||||
"org/jline/**",
|
||||
"org/json/**",
|
||||
"org/xmlpull/**",
|
||||
"*.txt")
|
||||
|
||||
val compilerJar = configurations.create("compilerJar")
|
||||
private fun ShadowJar.configureEmbeddableCompilerRelocation(withJavaxInject: Boolean = true) {
|
||||
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf")
|
||||
packagesToRelocate.forEach {
|
||||
relocate(it, "$kotlinEmbeddableRootPackage.$it")
|
||||
}
|
||||
if (withJavaxInject) {
|
||||
relocate("javax.inject", "$kotlinEmbeddableRootPackage.javax.inject")
|
||||
}
|
||||
relocate("org.fusesource", "$kotlinEmbeddableRootPackage.org.fusesource") {
|
||||
// TODO: remove "it." after #KT-12848 get addressed
|
||||
exclude("org.fusesource.jansi.internal.CLibrary")
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.compilerShadowJar(taskName: String, body: ShadowJar.() -> Unit): Jar {
|
||||
|
||||
val compilerJar = configurations.getOrCreate("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")
|
||||
body()
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.embeddableCompiler(taskName: String = "embeddable", body: ShadowJar.() -> Unit = {}): Jar =
|
||||
compilerShadowJar(taskName) {
|
||||
configureEmbeddableCompilerRelocation()
|
||||
body()
|
||||
}
|
||||
relocate("org.fusesource", "$kotlinEmbeddableRootPackage.org.fusesource") {
|
||||
// TODO: remove "it." after #KT-12848 get addressed
|
||||
exclude("org.fusesource.jansi.internal.CLibrary")
|
||||
|
||||
fun Project.compilerDummyForDependenciesRewriting(taskName: String = "compilerDummy", body: ShadowJar.() -> Unit = {}): Jar =
|
||||
compilerShadowJar(taskName) {
|
||||
exclude(packagesToExcludeFromDummy)
|
||||
body()
|
||||
}
|
||||
|
||||
const val COMPILER_DUMMY_JAR_CONFIGURATION_NAME = "compilerDummyJar"
|
||||
|
||||
fun Project.compilerDummyJar(task: Jar, body: Jar.() -> Unit = {}) {
|
||||
task.body()
|
||||
addArtifact(COMPILER_DUMMY_JAR_CONFIGURATION_NAME, task, task)
|
||||
}
|
||||
|
||||
fun Project.embeddableCompilerDummyForDependenciesRewriting(taskName: String = "embeddable", body: Jar.() -> Unit = {}): Jar {
|
||||
val compilerDummyJar = configurations.getOrCreate("compilerDummyJar")
|
||||
dependencies.add(compilerDummyJar.name,
|
||||
dependencies.project(":kotlin-compiler-embeddable", configuration = COMPILER_DUMMY_JAR_CONFIGURATION_NAME))
|
||||
|
||||
return task<ShadowJar>(taskName) {
|
||||
destinationDir = File(buildDir, "libs")
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
from(compilerDummyJar)
|
||||
configureEmbeddableCompilerRelocation(withJavaxInject = false)
|
||||
body()
|
||||
}
|
||||
}
|
||||
@@ -56,7 +117,7 @@ fun Project.rewriteDepsToShadedJar(originalJarTask: Jar, shadowJarTask: Zip, bod
|
||||
}
|
||||
shadowJarTask.apply {
|
||||
dependsOn(originalJarTask)
|
||||
from(originalJarTask)
|
||||
from(originalJarTask)// { include("**") }
|
||||
classifier = "shadow"
|
||||
}
|
||||
dependsOn(shadowJarTask)
|
||||
@@ -65,4 +126,5 @@ fun Project.rewriteDepsToShadedJar(originalJarTask: Jar, shadowJarTask: Zip, bod
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.rewriteDepsToShadedCompiler(originalJarTask: Jar, body: Jar.() -> Unit = {}): Jar = rewriteDepsToShadedJar(originalJarTask, embeddableCompiler(), body)
|
||||
fun Project.rewriteDepsToShadedCompiler(originalJarTask: Jar, body: Jar.() -> Unit = {}): Jar =
|
||||
rewriteDepsToShadedJar(originalJarTask, embeddableCompilerDummyForDependenciesRewriting(), body)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
description = "Annotation Processor wrapper for Kotlin"
|
||||
|
||||
@@ -22,12 +24,20 @@ projectTest {
|
||||
workingDir = projectDir
|
||||
}
|
||||
|
||||
val originalJar by task<ShadowJar> {
|
||||
from(packedJars)
|
||||
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
|
||||
}
|
||||
|
||||
runtimeJar(rewriteDepsToShadedCompiler(originalJar))
|
||||
//noDefaultJar()
|
||||
//tasks.remove(tasks.findByName("jar"))
|
||||
//
|
||||
//runtimeJar(task<ShadowJar>("jar")) {
|
||||
// from(packedJars)
|
||||
// from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
|
||||
// configureRelocation()
|
||||
//}
|
||||
runtimeJar(rewriteDepsToShadedCompiler(
|
||||
task<ShadowJar>("shadowJar") {
|
||||
from(packedJars)
|
||||
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
|
||||
}
|
||||
))
|
||||
sourcesJar()
|
||||
javadocJar()
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ dependencies {
|
||||
testCompile project(path: ':compiler:incremental-compilation-impl', configuration: 'tests-jar')
|
||||
|
||||
testCompile 'org.jetbrains.kotlin:gradle-api:2.2'
|
||||
|
||||
testRuntime project(path: ':kotlin-android-extensions', configuration: 'runtimeJar')
|
||||
}
|
||||
|
||||
test.dependsOn(":kotlin-allopen:install",
|
||||
|
||||
@@ -32,9 +32,9 @@ dependencies {
|
||||
compileOnly project(':compiler:incremental-compilation-impl')
|
||||
|
||||
compile project(':kotlin-stdlib')
|
||||
compile project(':kotlin-android-extensions')
|
||||
compile project(':kotlin-build-common')
|
||||
compile project(':kotlin-compiler-runner')
|
||||
compileOnly project(':kotlin-android-extensions')
|
||||
compileOnly project(':kotlin-build-common')
|
||||
compileOnly project(':kotlin-compiler-runner')
|
||||
compileOnly project(':kotlin-annotation-processing')
|
||||
compileOnly project(':kotlin-annotation-processing-gradle')
|
||||
|
||||
@@ -44,6 +44,8 @@ dependencies {
|
||||
|
||||
runtime project(path: ':kotlin-compiler-embeddable', configuration: "runtimeJar")
|
||||
runtime project(path: ':kotlin-annotation-processing-gradle', configuration: "runtimeJar")
|
||||
runtime project(path: ':kotlin-android-extensions', configuration: 'runtimeJar')
|
||||
runtime project(path: ':kotlin-compiler-runner', configuration: 'runtimeJar')
|
||||
|
||||
agp25CompileOnly 'com.android.tools.build:gradle:3.0.0-alpha1'
|
||||
agp25CompileOnly 'org.codehaus.groovy:groovy-all:2.3.9'
|
||||
@@ -53,6 +55,8 @@ dependencies {
|
||||
|
||||
testCompileOnly project(':compiler')
|
||||
testCompile project (path: ':kotlin-build-common', configuration: 'tests-jar')
|
||||
testCompile project(':kotlin-android-extensions')
|
||||
testCompile project(':kotlin-compiler-runner')
|
||||
testCompile project(':kotlin-test::kotlin-test-junit')
|
||||
testCompile "junit:junit:4.12"
|
||||
testCompileOnly project(':kotlin-annotation-processing')
|
||||
|
||||
@@ -6,13 +6,18 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(":kotlin-stdlib"))
|
||||
compile(project(":kotlin-script-runtime"))
|
||||
compile(project(":kotlin-reflect"))
|
||||
runtime(project(":kotlin-stdlib"))
|
||||
runtime(project(":kotlin-script-runtime"))
|
||||
runtime(project(":kotlin-reflect"))
|
||||
}
|
||||
|
||||
noDefaultJar()
|
||||
|
||||
// dummy is used for rewriting dependencies to the shaded packages in the embeddable compiler
|
||||
compilerDummyJar(compilerDummyForDependenciesRewriting("compilerDummy") {
|
||||
classifier = "dummy"
|
||||
})
|
||||
|
||||
runtimeJar(embeddableCompiler())
|
||||
|
||||
sourcesJar()
|
||||
|
||||
Reference in New Issue
Block a user