Shade shared classes in the gradle-plugin fat jar

This commit is contained in:
Ilya Matveev
2018-10-11 12:50:34 +03:00
committed by Ilya Matveev
parent b4a3bf0a6b
commit 5a37fe4e7e
3 changed files with 36 additions and 22 deletions
@@ -112,6 +112,7 @@ shadowJar {
classifier = null classifier = null
relocate('org.jetbrains.kotlinx', 'shadow.org.jetbrains.kotlinx') relocate('org.jetbrains.kotlinx', 'shadow.org.jetbrains.kotlinx')
relocate('org.jetbrains.kotlin.compilerRunner', 'shadow.org.jetbrains.kotlin.compilerRunner') relocate('org.jetbrains.kotlin.compilerRunner', 'shadow.org.jetbrains.kotlin.compilerRunner')
relocate('org.jetbrains.kotlin.konan', 'shadow.org.jetbrains.kotlin.konan')
relocate('org.jetbrains.kotlin.gradle', 'shadow.org.jetbrains.kotlin.gradle') { relocate('org.jetbrains.kotlin.gradle', 'shadow.org.jetbrains.kotlin.gradle') {
exclude('org.jetbrains.kotlin.gradle.plugin.experimental.**') exclude('org.jetbrains.kotlin.gradle.plugin.experimental.**')
exclude('org.jetbrains.kotlin.gradle.plugin.konan.**') exclude('org.jetbrains.kotlin.gradle.plugin.konan.**')
@@ -157,10 +158,6 @@ pluginUnderTestMetadata {
test { test {
dependsOn shadowJar dependsOn shadowJar
classpath = configurations.testRuntimeClasspath +
sourceSets.test.output +
files(shadowJar.archivePath) +
configurations.shadow
systemProperty("kotlin.version", kotlinVersion) systemProperty("kotlin.version", kotlinVersion)
systemProperty("kotlin.repo", kotlinCompilerRepo) systemProperty("kotlin.repo", kotlinCompilerRepo)
if (project.hasProperty("konan.home")) { if (project.hasProperty("konan.home")) {
@@ -847,23 +847,40 @@ class ExperimentalPluginTests {
@Test @Test
fun `Plugin should provide a correct serialization compiler plugin`() { fun `Plugin should provide a correct serialization compiler plugin`() {
withProject { val project = KonanProject.createEmpty(projectDirectory).apply {
pluginManager.apply("kotlinx-serialization-native") buildFile.writeText("""
repositories.apply { import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
jcenter()
maven { it.setUrl("http://kotlin.bintray.com/kotlin-eap") } plugins {
maven { it.setUrl("http://kotlin.bintray.com/kotlin-dev") } id 'kotlin-native'
maven { it.setUrl(MultiplatformSpecification.KOTLIN_REPO) } id 'kotlinx-serialization-native'
} }
evaluate()
tasks.withType(KotlinNativeCompile::class.java).all { repositories {
val compileClassPath = it.compilerPluginClasspath maven { url "http://kotlin.bintray.com/kotlin-eap" }
assertNotNull(compileClassPath) maven { url "http://kotlin.bintray.com/kotlin-dev" }
val files = compileClassPath.files maven { url "${MultiplatformSpecification.KOTLIN_REPO}" }
assertTrue(files.isNotEmpty(), "No compiler plugins in the classpath") }
assertEquals(1, files.size, "More than one compiler plugin in the classpath")
assertTrue(files.single().absolutePath.contains("kotlin-serialization-unshaded"), "No unshaded version of serialization plugin in the classpath") def assertTrue(boolean cond, String message) {
} if (!cond) {
throw AssertionError(message)
}
}
task assertClassPath {
doLast {
tasks.withType(KotlinNativeCompile.class).all {
def compileClassPath = it.compilerPluginClasspath
assertTrue(compileClassPath != null, "compileClassPath should not be null")
assertTrue(!compileClassPath.isEmpty(), "No compiler plugins in the classpath")
assertTrue(compileClassPath.singleFile.absolutePath.contains("kotlin-serialization-unshaded"),
"No unshaded version of serialization plugin in the classpath")
}
}
}
""".trimIndent())
} }
project.createRunner().withArguments("assertClassPath").build()
} }
} }
@@ -129,7 +129,7 @@ open class ToolingModelTests {
} }
import org.jetbrains.kotlin.gradle.plugin.model.* import org.jetbrains.kotlin.gradle.plugin.model.*
import org.jetbrains.kotlin.konan.target.CompilerOutputKind import shadow.org.jetbrains.kotlin.konan.target.CompilerOutputKind
public <T> void assertEquals( public <T> void assertEquals(
T actual, T actual,