From 65d8b8e7c14e4c0b94a2940d1188705a7acfac71 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 1 Oct 2018 14:36:17 +0300 Subject: [PATCH] Fix plugin uploading (#2157) * Fix plugin uploading * Fix plugin version in bundle samples * [gradle-plugin] Use unshaded compiler plugin configuration --- build.gradle | 7 +++++- .../kotlin-native-gradle-plugin/build.gradle | 17 ++++++++++---- .../plugins/KotlinNativeBasePlugin.kt | 12 +++++++--- .../test/kotlin/ExperimentalPluginTests.kt | 23 ++++++++++++++++++- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 6425b489681..2aeff611518 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,12 @@ ext { kotlinScriptRuntimeModule="org.jetbrains.kotlin:kotlin-script-runtime:${kotlinVersion}" konanVersionFull = KonanVersion.Companion.CURRENT - gradlePluginVersion = konanVersionFull.toString() + + if (konanVersionFull.meta == MetaVersion.RELEASE) { + gradlePluginVersion = kotlinVersion + } else { + gradlePluginVersion = "$kotlinVersion-native-${KonanVersion.Companion.CURRENT.toString()}" + } } allprojects { diff --git a/tools/kotlin-native-gradle-plugin/build.gradle b/tools/kotlin-native-gradle-plugin/build.gradle index 9426ce77a8e..80066e4e68d 100644 --- a/tools/kotlin-native-gradle-plugin/build.gradle +++ b/tools/kotlin-native-gradle-plugin/build.gradle @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.konan.KonanVersion import org.jetbrains.kotlin.konan.MetaVersion -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar /** * One may use bintrayUser/bintrayKey project properties or BINTRAY_USER/BINTRAY_KEY environment variables to upload @@ -101,7 +100,7 @@ dependencies { } } -task jar(type: ShadowJar, overwrite: true) { +shadowJar { from sourceSets.main.output configurations = [project.configurations.bundleDependencies] classifier = null @@ -126,14 +125,22 @@ task jar(type: ShadowJar, overwrite: true) { exclude('META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin') } -assemble.dependsOn shadowJar +jar { + dependsOn shadowJar + enabled = false +} pluginUnderTestMetadata { - dependsOn jar - pluginClasspath = files(jar.archivePath) + configurations.shadow + dependsOn shadowJar + pluginClasspath = files(shadowJar.archivePath) + configurations.shadow } test { + dependsOn shadowJar + classpath = configurations.testRuntimeClasspath + + sourceSets.test.output + + files(shadowJar.archivePath) + + configurations.shadow systemProperty("kotlin.version", buildKotlinVersion) systemProperty("kotlin.repo", buildKotlinCompilerRepo) if (project.hasProperty("konan.home")) { diff --git a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt index 73ccd4a674e..1cfa1a7d0bf 100644 --- a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt +++ b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/experimental/plugins/KotlinNativeBasePlugin.kt @@ -34,6 +34,7 @@ import org.gradle.language.plugins.NativeBasePlugin import org.gradle.nativeplatform.test.tasks.RunTestExecutable import org.gradle.util.GradleVersion import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.gradle.plugin.NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME import org.jetbrains.kotlin.gradle.plugin.PLUGIN_CLASSPATH_CONFIGURATION_NAME import org.jetbrains.kotlin.gradle.plugin.SubpluginEnvironment import org.jetbrains.kotlin.gradle.plugin.experimental.CInteropSettings @@ -130,8 +131,13 @@ class KotlinNativeBasePlugin: Plugin { assembleTask.dependsOn(it) } - project.configurations.maybeCreate(PLUGIN_CLASSPATH_CONFIGURATION_NAME).apply { - isTransitive = false + project.configurations.apply { + maybeCreate(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME).apply { + isTransitive = false + } + maybeCreate(PLUGIN_CLASSPATH_CONFIGURATION_NAME).apply { + isTransitive = false + } } components.withType(AbstractKotlinNativeBinary::class.java) { binary -> @@ -149,7 +155,7 @@ class KotlinNativeBasePlugin: Plugin { SubpluginEnvironment.loadSubplugins(this, kotlinVersion) .addSubpluginOptions(this, it, it.compilerPluginOptions) - it.compilerPluginClasspath = project.configurations.getByName(PLUGIN_CLASSPATH_CONFIGURATION_NAME) + it.compilerPluginClasspath = project.configurations.getByName(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME) // Register an API header produced for shared/static library as a task output. if (binary.kind == CompilerOutputKind.DYNAMIC || binary.kind == CompilerOutputKind.STATIC) { diff --git a/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt b/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt index e991def5595..23d812e78ae 100644 --- a/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt +++ b/tools/kotlin-native-gradle-plugin/src/test/kotlin/ExperimentalPluginTests.kt @@ -844,4 +844,25 @@ class ExperimentalPluginTests { } } } -} \ No newline at end of file + + @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") } + } + 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") + } + } + } +}