Skip to content

Commit

Permalink
bug: Add support for Kotlin 1.3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fabianishere committed Nov 7, 2018
1 parent 425a7bf commit 7dbb969
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 36 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ To use the plugin, just apply the plugin in your `build.gradle`:

```groovy
plugins {
id 'nl.fabianm.kotlin.plugin.generated' version '1.0'
id 'nl.fabianm.kotlin.plugin.generated' version '1.3.0'
}
```

Make sure you install the version that is compatible with the Kotlin
version you are using:

| **Kotlin** | **Plugin** |
|:----------:|:----------:|
| 1.2.* | 1.0 |
| 1.3.* | 1.3.0 |

You can optionally configure the plugin as shown below:

```groovy
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

allprojects {
group = 'nl.fabianm.kotlin.plugin.generated'
version = '1.0'
version = '1.3.0'

ext {
kotlin_version = '1.2.41'
junit_jupiter_version = '5.2.0'
junit_platform_version = '1.2.0'
kotlin_version = '1.3.0'
junit_jupiter_version = '5.3.1'
junit_platform_version = '1.3.1'
}
}

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 2 additions & 8 deletions plugin-compiler-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/

plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.0"
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"
id "jacoco"
id "org.jetbrains.kotlin.jvm" version "1.2.41"
id "org.jmailen.kotlinter" version "1.12.0"
}

def compilerPlugin = project(':plugin-compiler')
Expand Down Expand Up @@ -53,12 +53,6 @@ compileTestKotlin {
}
}

kotlin {
experimental {
coroutines "enable"
}
}

/* Test setup */
test {
useJUnitPlatform {}
Expand Down
4 changes: 2 additions & 2 deletions plugin-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

plugins {
id "org.jetbrains.kotlin.jvm" version "1.2.41"
id "org.jmailen.kotlinter" version "1.12.0"
id "org.jetbrains.kotlin.jvm" version "1.3.0"
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"
}

description = "A compiler plugin for Kotlin that marks Kotlin-generated code with an annotation."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import nl.fabianm.kotlin.plugin.generated.GeneratedConfigurationKeys.ANNOTATION
import nl.fabianm.kotlin.plugin.generated.GeneratedConfigurationKeys.DEFAULT_ANNOTATION
import nl.fabianm.kotlin.plugin.generated.GeneratedConfigurationKeys.VISIBLE
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
import org.jetbrains.kotlin.com.intellij.mock.MockProject
Expand Down Expand Up @@ -75,6 +76,8 @@ class GeneratedComponentRegistrar : ComponentRegistrar {
MessageCollector.NONE
)

messageCollector.report(CompilerMessageSeverity.INFO, "Generated: Compiler plugin activated")

ClassBuilderInterceptorExtension.registerExtensionAsFirst(
project,
GeneratedClassBuilderInterceptorExtension(
Expand Down
11 changes: 6 additions & 5 deletions plugin-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/

plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.0"
id "org.jlleitschuh.gradle.ktlint" version "6.2.1"

id "java-gradle-plugin"
id "maven-publish"
id "org.jetbrains.kotlin.jvm" version "1.2.41"
id "org.jmailen.kotlinter" version "1.12.0"
id "com.gradle.plugin-publish" version "0.9.10"
id "com.jfrog.bintray" version "1.8.0"
id "com.gradle.plugin-publish" version "0.10.0"
id "com.jfrog.bintray" version "1.8.4"
}

repositories {
Expand All @@ -30,7 +31,7 @@ repositories {
dependencies {
compile gradleApi()
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile "org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.2.41"
compile "org.jetbrains.kotlin:kotlin-gradle-plugin-api:${kotlin_version}"

compileOnly project(':plugin-compiler')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package nl.fabianm.kotlin.plugin.generated.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.compile.AbstractCompile
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

class GeneratedGradleSubplugin : Plugin<Project> {
Expand All @@ -40,23 +41,16 @@ class GeneratedGradleSubplugin : Plugin<Project> {
class GeneratedKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
companion object {
private const val GENERATED_ARTIFACT_NAME = "plugin-gradle"
private const val GENERATED_GROUP_NAME = "nl.fabianm.kotlin.plugin.generated"
private const val GENERATED_GROUP_ID = "nl.fabianm.kotlin.plugin.generated"
private const val GENERATED_VERSION = "1.3.0"
private const val GENERATED_COMPILER_PLUGIN_ID = "nl.fabianm.kotlin.plugin.generated"

private val ANNOTATION_ARG_NAME = "annotation"
private val VISIBLE_ARG_NAME = "visible"
}

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

override fun apply(
project: Project,
kotlinCompile: AbstractCompile,
javaCompile: AbstractCompile,
variantData: Any?,
androidProjectHandler: Any?,
javaSourceSet: SourceSet?
): List<SubpluginOption> {
override fun apply(project: Project, kotlinCompile: AbstractCompile, javaCompile: AbstractCompile?, variantData: Any?, androidProjectHandler: Any?, kotlinCompilation: KotlinCompilation?): List<SubpluginOption> {
if (!GeneratedGradleSubplugin.isEnabled(project)) {
return emptyList()
}
Expand All @@ -68,9 +62,8 @@ class GeneratedKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
)
}

override fun getCompilerPluginId() = GENERATED_COMPILER_PLUGIN_ID

override fun getArtifactName(): String = GENERATED_ARTIFACT_NAME
override fun getPluginArtifact(): SubpluginArtifact =
SubpluginArtifact(GENERATED_GROUP_ID, GENERATED_ARTIFACT_NAME, GENERATED_VERSION)

override fun getGroupName(): String = GENERATED_GROUP_NAME
override fun getCompilerPluginId() = GENERATED_COMPILER_PLUGIN_ID
}
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

rootProject.name = 'kotlin-plugin-generated'

enableFeaturePreview('STABLE_PUBLISHING')

include ':plugin-compiler'
include ':plugin-compiler-tests'
include ':plugin-gradle'

0 comments on commit 7dbb969

Please sign in to comment.