Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError when applying Gradle plugin from Gradle Plugin Portal #112

Open
gabrielhuff opened this issue Mar 20, 2020 · 1 comment

Comments

@gabrielhuff
Copy link

How to reproduce

The following minimal build.gradle:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.61'
    id "com.google.protobuf" version "0.8.12"
    id "com.github.marcoferrer.kroto-plus" version "0.6.1"
    id "idea"
}

krotoPlus {
    config {
        main {}
    }
}

Will throw an exception (I'm using Gradle 5.6). Specifically, running this:

$ ./gradlew

Will throw this:

...
Caused by: java.lang.NoClassDefFoundError: com/google/protobuf/MessageOrBuilder
        at com.github.marcoferrer.krotoplus.gradle.compiler.CompilerConfigWrapper.<init>(CompilerConfigWrapper.kt:46)
        at com.github.marcoferrer.krotoplus.gradle.KrotoPlusPluginExtension$config$1.create(KrotoPlusPluginExtension.kt:31)
        at com.github.marcoferrer.krotoplus.gradle.KrotoPlusPluginExtension$config$1.create(KrotoPlusPluginExtension.kt:26)
        at org.gradle.api.internal.FactoryNamedDomainObjectContainer.doCreate(FactoryNamedDomainObjectContainer.java:106)
 ...

What fixes it

Getting the buildscript dependency from maven central instead of the Gradle plugin portal will fix the problem:

buildscript { // <-- add this
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.github.marcoferrer.krotoplus:kroto-plus-gradle-plugin:0.6.1"
    }
}

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.61'
    id "com.google.protobuf" version "0.8.12"
    id "idea"
}

apply plugin: 'com.github.marcoferrer.kroto-plus' // <-- and this

krotoPlus {
    config {
        main {}
    }
}

Why this is happening

The plugin has a runtime dependency to com.google.protobuf:protobuf-java:3.9.0, which is not available on the Gradle Plugin Portal.


I just discovered this repo. You've done an amazing job! I've heard that Google is working on an official Kotlin API, but honestly it's going to be hard for them to catch up to this project :)

@marcoferrer
Copy link
Owner

Thanks for submitting this!
Since we aren’t embedding the dependency in within the plugin this error is expected. One alternative to adding the maven repository within the build script block is using the pluginManagement in settings.gradle

pluginManagement{
    repositories {
        gradlePluginPortal()
        jcenter()
    }
}

This would let you continue to use the plugins block in your build.gradle. Since this Gradle plugin is experimental your feedback might be a sign that we should consider embedding the dependency in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants