Why do I get UnknownPluginException when trying to use a custom Kotlin complier plugin in Gradle?

Issue

I have created a custom Kotlin compiler plugin for Gradle. It was inspired by kotlin-allopen (2) and sample-kotlin-compiler-plugin, and is supposed to make all Kotlin classes non-final.

The problem is, I’m unable to use it in my projects, I only get the following:

Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'no.synth.kotlin.plugins.kotlin-really-allopen' not found.
    at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:131)

I have tried both the “new” plugin syntax:

plugins {
  id "no.synth.kotlin.plugins.kotlin-really-allopen" version "0.1"
}

.. and the old one:

buildscript {
  repositories {
    mavenLocal()
  }
  dependencies {
    classpath "no.synth.kotlin.plugins:kotlin-really-allopen:0.1" 
  }
}

apply plugin: "kotlin-really-allopen" // I've tried "no.synth.kotlin.plugins.kotlin-really-allopen" as well

So what am I doing wrong? Here’s the plugin: https://github.com/henrik242/kotlin-really-allopen

EDIT: I have updated the repository with an example app and a README.md to easily reproduce the problem.

Solution

Your Gradle plugin doesn’t seem to contain any entry under META-INF/gradle-plugins.

Gradle requires that every plugin ID is mapped to the implementation class, and this mapping is stored in META-INF/gradle-plugins resources.

To map the plugin ID kotlin-really-allopen, you would need a resource file src/main/resources/META-INF/gradle-plugins/kotlin-really-allopen.properties.

See: Wiring for a custom plugin

You can also use the Gradle Plugin Development Plugin, which automatically generates these entries from the build script DSL.


Also, your repository doesn’t seem to contain an actual Gradle plugin implementation, there’s only the part that the compiler needs to load. For an example that contains the Gradle part too, take a look at kevinmost/debuglog.

Answered By – hotkey

Leave a Comment