diff --git a/README.md b/README.md index 48bf2ad..9062428 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.bnorm.power/kotlin-power-assert-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.bnorm.power/kotlin-power-assert-plugin) +> [!IMPORTANT] +> Starting with Kotlin 2.0.0, this compiler plugin has been replaced with an official Kotlin Power-Assert compiler +> plugin. As such, this compiler plugin is no longer supported, and any usage should be replaced with the official +> plugin. See https://kotl.in/power-assert for more information on build setup. + Kotlin Compiler Plugin which high-jacks Kotlin assert function calls and transforms them similar to [Groovy's Power Assert feature][groovy-power-assert]. This plugin uses the IR backend for the Kotlin compiler and supports all @@ -155,19 +160,20 @@ used. Check the table below to find when support for a particular version of Kotlin was first introduced. If a version of Kotlin or this plugin is not listed it can be assumed to maintain compatibility with the next oldest version listed. -| Kotlin Version | Plugin Version | -|----------------|----------------| -| 1.3.60 | 0.1.0 | -| 1.3.70 | 0.3.0 | -| 1.4.0 | 0.4.0 | -| 1.4.20 | 0.6.0 | -| 1.4.30 | 0.7.0 | -| 1.5.0 | 0.8.0 | -| 1.5.10 | 0.9.0 | -| 1.5.20 | 0.10.0 | -| 1.6.0 | 0.11.0 | -| 1.7.0 | 0.12.0 | -| 1.8.20 | 0.13.0 | +| Kotlin Version | Plugin Version | +|------------------|----------------------------------------------------------| +| 1.3.60 | 0.1.0 | +| 1.3.70 | 0.3.0 | +| 1.4.0 | 0.4.0 | +| 1.4.20 | 0.6.0 | +| 1.4.30 | 0.7.0 | +| 1.5.0 | 0.8.0 | +| 1.5.10 | 0.9.0 | +| 1.5.20 | 0.10.0 | +| 1.6.0 | 0.11.0 | +| 1.7.0 | 0.12.0 | +| 1.8.20 | 0.13.0 | +| 2.0.0 and beyond | Official support by Kotlin: https://kotl.in/power-assert | ## Kotlin IR diff --git a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt index 151f9cf..bbae02c 100644 --- a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt +++ b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt @@ -16,6 +16,10 @@ package com.bnorm.power +@Deprecated( + message = "Replace with the official Kotlin Power-Assert compiler plugin: https://kotl.in/power-assert", + level = DeprecationLevel.ERROR, +) open class PowerAssertGradleExtension { var functions: List = listOf("kotlin.assert") var excludedSourceSets: List = listOf() 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 aa061a5..28e7c3a 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,41 +16,27 @@ package com.bnorm.power +import org.gradle.api.GradleException +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 : KotlinCompilerPluginSupportPlugin { - override fun apply(target: Project): Unit = with(target) { - extensions.create("kotlinPowerAssert", PowerAssertGradleExtension::class.java) +class PowerAssertGradlePlugin : Plugin { + companion object { + private val DEPRECATION_EXCEPTION_MESSAGE = + "Starting with Kotlin 2.0.0, kotlin-power-assert is no longer supported. " + + "Please switch to the official Kotlin power-assert compiler plugin: https://kotl.in/power-assert" + + "\n\n" + + """ + Replace the kotlin-power-assert Gradle plugin with one of the following: + + plugins { + kotlin("plugin.power-assert") version "" // Kts format + id 'org.jetbrains.kotlin.plugin.power-assert' version '' // Groovy format + } + """.trimIndent() } - override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean { - val project = kotlinCompilation.target.project - val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) - return extension.excludedSourceSets.none { it == kotlinCompilation.defaultSourceSet.name } - } - - override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert" - - override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( - groupId = BuildConfig.PLUGIN_GROUP_ID, - artifactId = BuildConfig.PLUGIN_ARTIFACT_ID, - version = BuildConfig.PLUGIN_VERSION, - ) - - 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) - } - } + override fun apply(target: Project) { + throw GradleException(DEPRECATION_EXCEPTION_MESSAGE) } } diff --git a/kotlin-power-assert-plugin/build.gradle.kts b/kotlin-power-assert-plugin/build.gradle.kts index fc7bc5a..e5c9d02 100644 --- a/kotlin-power-assert-plugin/build.gradle.kts +++ b/kotlin-power-assert-plugin/build.gradle.kts @@ -29,6 +29,7 @@ tasks.withType { } tasks.withType { + enabled = false useJUnitPlatform() } diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt index f194d21..9f7eb7b 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt @@ -16,9 +16,9 @@ package com.bnorm.power -import com.bnorm.power.diagram.SourceFile import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.name.FqName @@ -27,10 +27,19 @@ class PowerAssertIrGenerationExtension( private val messageCollector: MessageCollector, private val functions: Set, ) : IrGenerationExtension { + companion object { + private val DEPRECATION_EXCEPTION_MESSAGE = + "Starting with Kotlin 2.0.0, kotlin-power-assert is no longer supported. " + + "Please switch to the official Kotlin power-assert compiler plugin: https://kotl.in/power-assert" + + "\n\n" + + """ + Replace the kotlin-power-assert compiler plugin artifact with one of the following: + - 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin:' + - 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin-embeddable:' + """.trimIndent() + } + override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { - for (file in moduleFragment.files) { - PowerAssertCallTransformer(SourceFile(file), pluginContext, messageCollector, functions) - .visitFile(file) - } + messageCollector.report(CompilerMessageSeverity.ERROR, DEPRECATION_EXCEPTION_MESSAGE) } } diff --git a/sample/settings.gradle.kts b/sample/settings.gradle.kts index 1bf631e..d3843b9 100644 --- a/sample/settings.gradle.kts +++ b/sample/settings.gradle.kts @@ -1,3 +1 @@ rootProject.name = "kotlin-power-assert-sample" - -includeBuild("..")