From d20fc12a08f8d36657e2856e3e843dad4088cff8 Mon Sep 17 00:00:00 2001 From: ilmat192 Date: Thu, 12 Jul 2018 12:00:30 +0700 Subject: [PATCH] [gradle-plugin] Publish the plugin to plugin portal (#1789) * [gradle-plugin] Publish the plugin to plugin portal * [gradle-plugin] Fix test classpath --- GRADLE_PLUGIN.md | 25 ++-- build.gradle | 4 + .../kotlin-native-gradle-plugin/build.gradle | 111 +++++++++++++----- 3 files changed, 100 insertions(+), 40 deletions(-) diff --git a/GRADLE_PLUGIN.md b/GRADLE_PLUGIN.md index e3a41c53b25..6435534dd24 100644 --- a/GRADLE_PLUGIN.md +++ b/GRADLE_PLUGIN.md @@ -8,8 +8,17 @@ plugins than the old one. The plugin is at an early stage so some things may be ## Overview -You may use the Gradle plugin to build _Kotlin/Native_ projects. To use it you need to include the following snippet in a build script -(see projects in `samples` directory): +You may use the Gradle plugin to build _Kotlin/Native_ projects. Since version 0.8 release builds of the plugin are +[available](https://plugins.gradle.org/plugin/org.jetbrains.kotlin.konan) at the Gradle plugin portal so you can apply it +using Gradle plugin DSL: + + plugins { + id "org.jetbrains.kotlin.konan" version "0.8" + } + +You also can get the plugin from a Bintray repository. In addition to releases this repo contains old and development +versions of the plugin which are not available at the plugin portal. To get the plugin from the Bintray repo, include +the following snippet in your build script: buildscript { repositories { @@ -18,22 +27,22 @@ You may use the Gradle plugin to build _Kotlin/Native_ projects. To use it you n url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" } } - + dependencies { - classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:*" + classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:0.8-dev-*" } } - + apply plugin: 'konan' The Kotlin/Native plugin depends on `org.jetbrains.kotlin:kotlin-gradle-plugin`. So if a build contains both these plugins as buildscript dependencies, it's recommended to **declare them in the same `build.gradle`** to avoid issues with plugin classpath. -If you already downloaded the compiler manually you may specify the path to its root directory using `konan.home` -project property (e.g. in `gradle.properties`). +By default the plugin downloads the Kotlin/Native compiler during the first run. If you already downloaded the compiler +manually you may specify the path to its root directory using `konan.home` project property (e.g. in `gradle.properties`). - konan.home=/home/user/kotlin-native-0.5 + konan.home=/home/user/kotlin-native-0.8 In this case the compiler will not be downloaded by the plugin. diff --git a/build.gradle b/build.gradle index f9387620d43..938ddd708c2 100644 --- a/build.gradle +++ b/build.gradle @@ -173,6 +173,10 @@ task gradlePluginCheck() { task gradlePluginUpload { dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':bintrayUpload') + // Don't publish dev builds to the plugin portal. + if (konanVersionFull.meta != MetaVersion.DEV) { + dependsOn gradle.includedBuild('kotlin-native-gradle-plugin').task(':publishPlugins') + } } task dist_compiler(dependsOn: "distCompiler") diff --git a/tools/kotlin-native-gradle-plugin/build.gradle b/tools/kotlin-native-gradle-plugin/build.gradle index 4e509ee7085..a3d7544cf74 100644 --- a/tools/kotlin-native-gradle-plugin/build.gradle +++ b/tools/kotlin-native-gradle-plugin/build.gradle @@ -39,6 +39,11 @@ buildscript { classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.2' } } + +plugins { + id 'com.gradle.plugin-publish' version '0.9.10' +} + apply plugin: 'java-gradle-plugin' apply plugin: 'kotlin' apply plugin: 'groovy' @@ -60,20 +65,23 @@ configurations { bundleDependencies { transitive = false } + + implementation.extendsFrom shadow + compileOnly.extendsFrom bundleDependencies + testImplementation.extendsFrom bundleDependencies } dependencies { - compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion" - compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion" - compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$buildKotlinVersion" + shadow "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion" + shadow "org.jetbrains.kotlin:kotlin-gradle-plugin:$buildKotlinVersion" bundleDependencies "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion" - testCompile 'junit:junit:4.12' - testCompile "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion" - testCompile "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion" - testCompile "org.tools4j:tools4j-spockito:1.6" - testCompile('org.spockframework:spock-core:1.1-groovy-2.4') { + testImplementation 'junit:junit:4.12' + testImplementation "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion" + testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion" + testImplementation "org.tools4j:tools4j-spockito:1.6" + testImplementation('org.spockframework:spock-core:1.1-groovy-2.4') { exclude module: 'groovy-all' } } @@ -89,6 +97,11 @@ shadowJar { assemble.dependsOn shadowJar +pluginUnderTestMetadata { + dependsOn shadowJar + pluginClasspath = files(shadowJar.archivePath) + configurations.shadow +} + test { systemProperty("kotlin.version", buildKotlinVersion) if (project.hasProperty("konan.home")) { @@ -108,12 +121,9 @@ test { if (project.hasProperty("filter")) { filter.includeTestsMatching project.property("filter") } - } processResources { - // We add konanVersion as a task input to avoid considering this task up-to-date when - // konanVersion is actually changed and should be updated in the plugin jar. from(file("$rootBuildDirectory/utilities/env_blacklist")) } @@ -121,24 +131,10 @@ compileTestGroovy.dependsOn.remove('compileTestJava') compileTestKotlin.dependsOn compileTestGroovy compileTestKotlin.classpath += files(compileTestGroovy.destinationDir) -// TODO: Get rid of manual pom generation. publishing { publications { - gradlePlugin(MavenPublication) { - artifact shadowJar - pom.withXml { XmlProvider xml -> - def deps = xml.asNode().appendNode("dependencies") - - def stdlibDep = deps.appendNode("dependency") - stdlibDep.appendNode("groupId", "org.jetbrains.kotlin") - stdlibDep.appendNode("artifactId", "kotlin-stdlib") - stdlibDep.appendNode("version", "$buildKotlinVersion") - - def kotlinPluginDep = deps.appendNode("dependency") - kotlinPluginDep.appendNode("groupId", "org.jetbrains.kotlin") - kotlinPluginDep.appendNode("artifactId", "kotlin-gradle-plugin") - kotlinPluginDep.appendNode("version", "$buildKotlinVersion") - } + gradlePlugin(MavenPublication) { publication -> + project.shadow.component(publication) } } } @@ -164,25 +160,76 @@ bintray { gradlePlugin { plugins { - create("konan") { + create('konan') { id = 'konan' implementationClass = 'org.jetbrains.kotlin.gradle.plugin.KonanPlugin' } - create("kotlin-native") { + create('kotlin-native') { id = 'kotlin-native' implementationClass = 'org.jetbrains.kotlin.gradle.plugin.experimental.plugins.KotlinNativePlugin' } - create("kotlin-platform-native") { + create('kotlin-platform-native') { id = 'kotlin-platform-native' implementationClass = 'org.jetbrains.kotlin.gradle.plugin.experimental.plugins.KotlinPlatformNativePlugin' } - create("org.jetbrains.kotlin.native"){ + + create('org.jetbrains.kotlin.konan') { + id = 'org.jetbrains.kotlin.konan' + implementationClass = 'org.jetbrains.kotlin.gradle.plugin.KonanPlugin' + } + create('org.jetbrains.kotlin.native') { id = 'org.jetbrains.kotlin.native' implementationClass = 'org.jetbrains.kotlin.gradle.plugin.experimental.plugins.KotlinNativePlugin' } - create("org.jetbrains.kotlin.platform.native") { + create('org.jetbrains.kotlin.platform.native') { id = 'org.jetbrains.kotlin.platform.native' implementationClass = 'org.jetbrains.kotlin.gradle.plugin.experimental.plugins.KotlinPlatformNativePlugin' } } } + +// Replace the default output jars with the fat-jar created by the shadowJar task. +configurations.archives.artifacts.clear() + +artifacts { + archives shadowJar +} + +pluginBundle { + website = 'https://kotlinlang.org/' + vcsUrl = 'https://github.com/JetBrains/kotlin-native' + description = 'Kotlin/Native plugins for Gradle' + tags = ['kotlin'] + + mavenCoordinates { + groupId = "org.jetbrains.kotlin" + } + + plugins { + konan { + id = 'org.jetbrains.kotlin.konan' + description = displayName = 'Kotlin/Native plugin' + } + kotlinNative { + id = 'org.jetbrains.kotlin.native' + displayName = 'Experimental Kotlin/Native plugin' + description = """\ + An experimental Kotlin/Native plugin integrated with Gradle support for native languages and + providing a new DSL which is much closer to the DSL of Kotlin/JVM and Kotlin/JS plugins. + + The plugin is intended for projects containing only Kotlin/Native code (without common modules). + For multiplatform development see https://plugins.gradle.org/plugin/org.jetbrains.kotlin.platform.native. + """.stripIndent() + } + kotlinPlatformNative { + id = 'org.jetbrains.kotlin.platform.native' + displayName = 'Experimental Kotlin/Native plugin for multiplatform development' + description = """\ + An experimental Kotlin/Native plugin integrated with Gradle support for native languages and + providing a new DSL which is much closer to the DSL of Kotlin/JVM and Kotlin/JS plugins. + + The plugin is intended for native parts of multiplatform projects. + """.stripIndent() + } + } +}