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
relocate('org.jetbrains.kotlinx', 'shadow.org.jetbrains.kotlinx')
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') {
exclude('org.jetbrains.kotlin.gradle.plugin.experimental.**')
exclude('org.jetbrains.kotlin.gradle.plugin.konan.**')
@@ -157,10 +158,6 @@ pluginUnderTestMetadata {
test {
dependsOn shadowJar
classpath = configurations.testRuntimeClasspath +
sourceSets.test.output +
files(shadowJar.archivePath) +
configurations.shadow
systemProperty("kotlin.version", kotlinVersion)
systemProperty("kotlin.repo", kotlinCompilerRepo)
if (project.hasProperty("konan.home")) {
@@ -847,23 +847,40 @@ class ExperimentalPluginTests {
@Test
fun `Plugin should provide a correct serialization compiler plugin`() {
withProject {
pluginManager.apply("kotlinx-serialization-native")
repositories.apply {
jcenter()
maven { it.setUrl("http://kotlin.bintray.com/kotlin-eap") }
maven { it.setUrl("http://kotlin.bintray.com/kotlin-dev") }
maven { it.setUrl(MultiplatformSpecification.KOTLIN_REPO) }
}
evaluate()
tasks.withType(KotlinNativeCompile::class.java).all {
val compileClassPath = it.compilerPluginClasspath
assertNotNull(compileClassPath)
val files = compileClassPath.files
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")
}
val project = KonanProject.createEmpty(projectDirectory).apply {
buildFile.writeText("""
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
plugins {
id 'kotlin-native'
id 'kotlinx-serialization-native'
}
repositories {
maven { url "http://kotlin.bintray.com/kotlin-eap" }
maven { url "http://kotlin.bintray.com/kotlin-dev" }
maven { url "${MultiplatformSpecification.KOTLIN_REPO}" }
}
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.konan.target.CompilerOutputKind
import shadow.org.jetbrains.kotlin.konan.target.CompilerOutputKind
public <T> void assertEquals(
T actual,