From c1a21b2aa27cde7bef8002e40b728d9f18d6d7f3 Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Tue, 18 Aug 2020 22:38:21 -0500 Subject: [PATCH] Fix Gradle subplugin deprecation --- kotlin-power-assert-gradle/build.gradle.kts | 3 - .../bnorm/power/PowerAssertGradlePlugin.kt | 32 +++++++++- .../bnorm/power/PowerAssertGradleSubplugin.kt | 58 ------------------- .../power/PowerAssertCommandLineProcessor.kt | 1 + sample/build.gradle.kts | 23 +------- 5 files changed, 32 insertions(+), 85 deletions(-) delete mode 100644 kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt diff --git a/kotlin-power-assert-gradle/build.gradle.kts b/kotlin-power-assert-gradle/build.gradle.kts index 98715dc02b1..8db7bc1d4be 100644 --- a/kotlin-power-assert-gradle/build.gradle.kts +++ b/kotlin-power-assert-gradle/build.gradle.kts @@ -11,9 +11,6 @@ plugins { dependencies { implementation(kotlin("stdlib")) implementation(kotlin("gradle-plugin-api")) - - kapt("com.google.auto.service:auto-service:1.0-rc6") - compileOnly("com.google.auto.service:auto-service-annotations:1.0-rc6") } pluginBundle { diff --git a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt index a4a4f35705d..be3591f667c 100644 --- a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt +++ b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt @@ -16,11 +16,37 @@ package com.bnorm.power -import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.provider.Provider +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin +import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact +import org.jetbrains.kotlin.gradle.plugin.SubpluginOption -class PowerAssertGradlePlugin : Plugin { - override fun apply(project: Project): Unit = with(project) { +class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin { + override fun apply(target: Project): Unit = with(target) { extensions.create("kotlinPowerAssert", PowerAssertGradleExtension::class.java) } + + override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true + + override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert" + + override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( + groupId = "com.bnorm.power", + artifactId = "kotlin-power-assert", + version = "0.4.0-SNAPSHOT" + ) + + override fun applyToCompilation( + kotlinCompilation: KotlinCompilation<*> + ): Provider> { + val project = kotlinCompilation.target.project + val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) + return project.provider { + extension.functions.map { + SubpluginOption(key = "function", value = it) + } + } + } } diff --git a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt deleted file mode 100644 index dda483ad410..00000000000 --- a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2020 Brian Norman - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.bnorm.power - -import com.google.auto.service.AutoService -import org.gradle.api.Project -import org.gradle.api.tasks.compile.AbstractCompile -import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation -import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin -import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact -import org.jetbrains.kotlin.gradle.plugin.SubpluginOption - -@AutoService(KotlinGradleSubplugin::class) -class PowerAssertGradleSubplugin : KotlinGradleSubplugin { - - override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert" - - override fun isApplicable(project: Project, task: AbstractCompile): Boolean = - project.plugins.hasPlugin(PowerAssertGradlePlugin::class.java) - - - override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( - groupId = "com.bnorm.power", - artifactId = "kotlin-power-assert", - version = "0.4.0-SNAPSHOT" - ) - - override fun apply( - project: Project, - kotlinCompile: AbstractCompile, - javaCompile: AbstractCompile?, - variantData: Any?, - androidProjectHandler: Any?, - kotlinCompilation: KotlinCompilation? - ): List { - val extension = project.extensions.findByType(PowerAssertGradleExtension::class.java) - ?: PowerAssertGradleExtension() - - return extension.functions.map { - SubpluginOption(key = "function", value = it) - } - } -} diff --git a/kotlin-power-assert/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt b/kotlin-power-assert/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt index bac096fadb0..a526f5e8e56 100644 --- a/kotlin-power-assert/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt +++ b/kotlin-power-assert/src/main/kotlin/com/bnorm/power/PowerAssertCommandLineProcessor.kt @@ -31,6 +31,7 @@ class PowerAssertCommandLineProcessor : CommandLineProcessor { optionName = "function", valueDescription = "function full-qualified name", description = "fully qualified path of function to intercept", + required = false, // TODO required for Kotlin/JS allowMultipleOccurrences = true ) ) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index e4686d7fe6b..c7fa53aca58 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -5,7 +5,7 @@ buildscript { } plugins { - kotlin("multiplatform") version "1.3.70" + kotlin("multiplatform") version "1.4.0" } apply(plugin = "com.bnorm.power.kotlin-power-assert") @@ -23,15 +23,9 @@ kotlin { } } } - js { + js(IR) { browser() nodejs() - - compilations.all { - kotlinOptions { - kotlinOptions.freeCompilerArgs += listOf("-Xir-produce-klib-dir", "-Xir-produce-js") - } - } } val osName = System.getProperty("os.name") @@ -43,9 +37,6 @@ kotlin { sourceSets { val commonMain by getting { - dependencies { - implementation(kotlin("stdlib")) - } } val commonTest by getting { dependencies { @@ -53,21 +44,11 @@ kotlin { implementation(kotlin("test-annotations-common")) } } - val jvmMain by getting { - dependencies { - implementation(kotlin("stdlib-jdk8")) - } - } val jvmTest by getting { dependencies { implementation(kotlin("test-junit")) } } - val jsMain by getting { - dependencies { - implementation(kotlin("stdlib-js")) - } - } val jsTest by getting { dependencies { implementation(kotlin("test-js"))