Skip to content

Commit 7dbb969

Browse files
committed
bug: Add support for Kotlin 1.3
The release of Kotlin 1.3 changed its plugin interface, which caused the plugin to fail with an AbstractMethodError. This commit updates the plugin to use the new plugin interface. Fixes #5
1 parent 425a7bf commit 7dbb969

File tree

10 files changed

+37
-36
lines changed

10 files changed

+37
-36
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ To use the plugin, just apply the plugin in your `build.gradle`:
2525

2626
```groovy
2727
plugins {
28-
id 'nl.fabianm.kotlin.plugin.generated' version '1.0'
28+
id 'nl.fabianm.kotlin.plugin.generated' version '1.3.0'
2929
}
3030
```
3131

32+
Make sure you install the version that is compatible with the Kotlin
33+
version you are using:
34+
35+
| **Kotlin** | **Plugin** |
36+
|:----------:|:----------:|
37+
| 1.2.* | 1.0 |
38+
| 1.3.* | 1.3.0 |
39+
3240
You can optionally configure the plugin as shown below:
3341

3442
```groovy

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
allprojects {
1818
group = 'nl.fabianm.kotlin.plugin.generated'
19-
version = '1.0'
19+
version = '1.3.0'
2020

2121
ext {
22-
kotlin_version = '1.2.41'
23-
junit_jupiter_version = '5.2.0'
24-
junit_platform_version = '1.2.0'
22+
kotlin_version = '1.3.0'
23+
junit_jupiter_version = '5.3.1'
24+
junit_platform_version = '1.3.1'
2525
}
2626
}
2727

gradle/wrapper/gradle-wrapper.jar

1.72 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

plugin-compiler-tests/build.gradle

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616

1717
plugins {
18+
id "org.jetbrains.kotlin.jvm" version "1.3.0"
19+
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"
1820
id "jacoco"
19-
id "org.jetbrains.kotlin.jvm" version "1.2.41"
20-
id "org.jmailen.kotlinter" version "1.12.0"
2121
}
2222

2323
def compilerPlugin = project(':plugin-compiler')
@@ -53,12 +53,6 @@ compileTestKotlin {
5353
}
5454
}
5555

56-
kotlin {
57-
experimental {
58-
coroutines "enable"
59-
}
60-
}
61-
6256
/* Test setup */
6357
test {
6458
useJUnitPlatform {}

plugin-compiler/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616

1717
plugins {
18-
id "org.jetbrains.kotlin.jvm" version "1.2.41"
19-
id "org.jmailen.kotlinter" version "1.12.0"
18+
id "org.jetbrains.kotlin.jvm" version "1.3.0"
19+
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"
2020
}
2121

2222
description = "A compiler plugin for Kotlin that marks Kotlin-generated code with an annotation."

plugin-compiler/src/main/kotlin/nl/fabianm/kotlin/plugin/generated/GeneratedPlugin.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import nl.fabianm.kotlin.plugin.generated.GeneratedConfigurationKeys.ANNOTATION
2020
import nl.fabianm.kotlin.plugin.generated.GeneratedConfigurationKeys.DEFAULT_ANNOTATION
2121
import nl.fabianm.kotlin.plugin.generated.GeneratedConfigurationKeys.VISIBLE
2222
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
23+
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
2324
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
2425
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
2526
import org.jetbrains.kotlin.com.intellij.mock.MockProject
@@ -75,6 +76,8 @@ class GeneratedComponentRegistrar : ComponentRegistrar {
7576
MessageCollector.NONE
7677
)
7778

79+
messageCollector.report(CompilerMessageSeverity.INFO, "Generated: Compiler plugin activated")
80+
7881
ClassBuilderInterceptorExtension.registerExtensionAsFirst(
7982
project,
8083
GeneratedClassBuilderInterceptorExtension(

plugin-gradle/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
*/
1616

1717
plugins {
18+
id "org.jetbrains.kotlin.jvm" version "1.3.0"
19+
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"
20+
1821
id "java-gradle-plugin"
1922
id "maven-publish"
20-
id "org.jetbrains.kotlin.jvm" version "1.2.41"
21-
id "org.jmailen.kotlinter" version "1.12.0"
22-
id "com.gradle.plugin-publish" version "0.9.10"
23-
id "com.jfrog.bintray" version "1.8.0"
23+
id "com.gradle.plugin-publish" version "0.10.0"
24+
id "com.jfrog.bintray" version "1.8.4"
2425
}
2526

2627
repositories {
@@ -30,7 +31,7 @@ repositories {
3031
dependencies {
3132
compile gradleApi()
3233
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
33-
compile "org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.2.41"
34+
compile "org.jetbrains.kotlin:kotlin-gradle-plugin-api:${kotlin_version}"
3435

3536
compileOnly project(':plugin-compiler')
3637
}

plugin-gradle/src/main/kotlin/nl/fabianm/kotlin/plugin/generated/gradle/GeneratedSubplugin.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ package nl.fabianm.kotlin.plugin.generated.gradle
1818

1919
import org.gradle.api.Plugin
2020
import org.gradle.api.Project
21-
import org.gradle.api.tasks.SourceSet
2221
import org.gradle.api.tasks.compile.AbstractCompile
22+
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
2323
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
24+
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
2425
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
2526

2627
class GeneratedGradleSubplugin : Plugin<Project> {
@@ -40,23 +41,16 @@ class GeneratedGradleSubplugin : Plugin<Project> {
4041
class GeneratedKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
4142
companion object {
4243
private const val GENERATED_ARTIFACT_NAME = "plugin-gradle"
43-
private const val GENERATED_GROUP_NAME = "nl.fabianm.kotlin.plugin.generated"
44+
private const val GENERATED_GROUP_ID = "nl.fabianm.kotlin.plugin.generated"
45+
private const val GENERATED_VERSION = "1.3.0"
4446
private const val GENERATED_COMPILER_PLUGIN_ID = "nl.fabianm.kotlin.plugin.generated"
45-
4647
private val ANNOTATION_ARG_NAME = "annotation"
4748
private val VISIBLE_ARG_NAME = "visible"
4849
}
4950

5051
override fun isApplicable(project: Project, task: AbstractCompile) = GeneratedGradleSubplugin.isEnabled(project)
5152

52-
override fun apply(
53-
project: Project,
54-
kotlinCompile: AbstractCompile,
55-
javaCompile: AbstractCompile,
56-
variantData: Any?,
57-
androidProjectHandler: Any?,
58-
javaSourceSet: SourceSet?
59-
): List<SubpluginOption> {
53+
override fun apply(project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?, kotlinCompilation: KotlinCompilation?): List<SubpluginOption> {
6054
if (!GeneratedGradleSubplugin.isEnabled(project)) {
6155
return emptyList()
6256
}
@@ -68,9 +62,8 @@ class GeneratedKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
6862
)
6963
}
7064

71-
override fun getCompilerPluginId() = GENERATED_COMPILER_PLUGIN_ID
72-
73-
override fun getArtifactName(): String = GENERATED_ARTIFACT_NAME
65+
override fun getPluginArtifact(): SubpluginArtifact =
66+
SubpluginArtifact(GENERATED_GROUP_ID, GENERATED_ARTIFACT_NAME, GENERATED_VERSION)
7467

75-
override fun getGroupName(): String = GENERATED_GROUP_NAME
68+
override fun getCompilerPluginId() = GENERATED_COMPILER_PLUGIN_ID
7669
}

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
rootProject.name = 'kotlin-plugin-generated'
1818

19+
enableFeaturePreview('STABLE_PUBLISHING')
20+
1921
include ':plugin-compiler'
2022
include ':plugin-compiler-tests'
2123
include ':plugin-gradle'

0 commit comments

Comments
 (0)