|
16 | 16 |
|
17 | 17 | package com.bnorm.power
|
18 | 18 |
|
| 19 | +import org.gradle.api.GradleException |
| 20 | +import org.gradle.api.Plugin |
19 | 21 | import org.gradle.api.Project
|
20 |
| -import org.gradle.api.provider.Provider |
21 |
| -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation |
22 |
| -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin |
23 |
| -import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact |
24 |
| -import org.jetbrains.kotlin.gradle.plugin.SubpluginOption |
25 | 22 |
|
26 |
| -class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin { |
27 |
| - override fun apply(target: Project): Unit = with(target) { |
28 |
| - extensions.create("kotlinPowerAssert", PowerAssertGradleExtension::class.java) |
| 23 | +class PowerAssertGradlePlugin : Plugin<Project> { |
| 24 | + companion object { |
| 25 | + private val DEPRECATION_EXCEPTION_MESSAGE = |
| 26 | + "Starting with Kotlin 2.0.0, kotlin-power-assert is no longer supported. " + |
| 27 | + "Please switch to the official Kotlin power-assert compiler plugin: https://kotl.in/power-assert" + |
| 28 | + "\n\n" + |
| 29 | + """ |
| 30 | + Replace the kotlin-power-assert Gradle plugin with one of the following: |
| 31 | + |
| 32 | + plugins { |
| 33 | + kotlin("plugin.power-assert") version "<kotlin-version>" // Kts format |
| 34 | + id 'org.jetbrains.kotlin.plugin.power-assert' version '<kotlin-version>' // Groovy format |
| 35 | + } |
| 36 | + """.trimIndent() |
29 | 37 | }
|
30 | 38 |
|
31 |
| - override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean { |
32 |
| - val project = kotlinCompilation.target.project |
33 |
| - val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) |
34 |
| - return extension.excludedSourceSets.none { it == kotlinCompilation.defaultSourceSet.name } |
35 |
| - } |
36 |
| - |
37 |
| - override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert" |
38 |
| - |
39 |
| - override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( |
40 |
| - groupId = BuildConfig.PLUGIN_GROUP_ID, |
41 |
| - artifactId = BuildConfig.PLUGIN_ARTIFACT_ID, |
42 |
| - version = BuildConfig.PLUGIN_VERSION, |
43 |
| - ) |
44 |
| - |
45 |
| - override fun applyToCompilation( |
46 |
| - kotlinCompilation: KotlinCompilation<*>, |
47 |
| - ): Provider<List<SubpluginOption>> { |
48 |
| - val project = kotlinCompilation.target.project |
49 |
| - val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java) |
50 |
| - return project.provider { |
51 |
| - extension.functions.map { |
52 |
| - SubpluginOption(key = "function", value = it) |
53 |
| - } |
54 |
| - } |
| 39 | + override fun apply(target: Project) { |
| 40 | + throw GradleException(DEPRECATION_EXCEPTION_MESSAGE) |
55 | 41 | }
|
56 | 42 | }
|
0 commit comments