HewlettPackard / kraal

Enables the use of Kotlin coroutines and GraalVM native-image together
MIT License
84 stars 2 forks source link

Could not create an instance of type com.hpe.kraal.gradle.KraalExtension_Decorated. #2

Open viniciusccarvalho opened 5 years ago

viniciusccarvalho commented 5 years ago

Hi there, after giving up on trying ktor with graal I found this, and I was so happy to see someone is looking into this.

But I could not manage to get the simplest gradle (groovy not kotlin) project started.

I get the following error when trying to build the project:

An exception occurred applying plugin request [id: 'com.hpe.kraal', version: '0.0.15']
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:232)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugins(DefaultPluginRequestApplicator.java:148)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:186)
    at org.gradle.configuration.BuildOperationScriptPlugin$1$1.run(BuildOperationScriptPlugin.java:69)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:66)
    at org.gradle.configuration.BuildOperationScriptPlugin$1.execute(BuildOperationScriptPlugin.java:63)
    at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:48)
    at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:63)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:41)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.run(LifecycleProjectEvaluator.java:105)
    ... 89 more
Caused by: org.gradle.api.plugins.InvalidPluginException: An exception occurred applying plugin request [id: 'com.hpe.kraal', version: '0.0.15']
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.exceptionOccurred(DefaultPluginRequestApplicator.java:247)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:229)
    ... 105 more
Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id 'com.hpe.kraal']
    at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:160)
    at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:130)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator$3.run(DefaultPluginRequestApplicator.java:151)
    at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.applyPlugin(DefaultPluginRequestApplicator.java:225)
    ... 105 more
Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type com.hpe.kraal.gradle.KraalExtension_Decorated.
Caused by: java.lang.NoSuchMethodError: org.gradle.api.model.ObjectFactory.fileCollection()Lorg/gradle/api/file/ConfigurableFileCollection;
    at com.hpe.kraal.gradle.KraalExtension.<init>(KraalExtension.kt:32)
    at com.hpe.kraal.gradle.KraalExtension_Decorated.<init>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.gradle.internal.reflect.DirectInstantiator.newInstance(DirectInstantiator.java:51)
    ... 127 more

And here's my build.gradle file:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.3'
    }
}

plugins {
    id "com.hpe.kraal" version "0.0.15"
}

apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: "com.github.johnrengelman.shadow"

group 'jetty-graal'
version '0.0.1-SNAPSHOT'
mainClassName = "io.igx.kotlin.ApplicationKt"

sourceSets {
    main.kotlin.srcDirs = main.java.srcDirs = ['src']
    test.kotlin.srcDirs = test.java.srcDirs = ['test']
    main.resources.srcDirs = ['resources']
    test.resources.srcDirs = ['testresources']
}

repositories {
    mavenLocal()
    jcenter()
    maven { url 'https://kotlin.bintray.com/ktor' }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    compile "io.ktor:ktor-server-cio:$ktor_version"
    compile "ch.qos.logback:logback-classic:$logback_version"
    compile "io.ktor:ktor-server-core:$ktor_version"
    compile "io.ktor:ktor-gson:$ktor_version"
    testCompile "io.ktor:ktor-server-tests:$ktor_version"
}

Any ideas?

bradnewman commented 5 years ago

Are you able to build the Gradle example with the Kotlin DSL build file? What version of Gradle are you using with this project? The fileCollection() method that's getting NoSuchMethodError was added very recently, in Gradle 5.3 - so I'm guessing you're using an older version?

viniciusccarvalho commented 5 years ago

Yep, it was a 5.3 issue. After upgrading it got partially fixed :)

Because I'm using the groovy version I did not include all the parts of the Kotlin DSL, I believe the new error now is due missing some of the tasks.

Thanks

viniciusccarvalho commented 5 years ago

Any chance you can provide a regular build.gradle (groovy) example? Also I could not figure out how to combine it with the shadow plugin that I usually have for the fatjar creation. It complains about a property from the jar task : runtimeClassPath not being found.

Regards

MrBergin commented 5 years ago

@viniciusccarvalho I had the same issue when I called the kraal plugin before the kotlin jvm plugin, here's what I had (in Kotlin DSL):

Broken:

plugins {
    val kotlinVersion by System.getProperties()
    val kraalVersion by System.getProperties()

    id("com.hpe.kraal") version "$kraalVersion"
    kotlin("jvm") version "$kotlinVersion"
}

Fixed:

plugins {
    val kotlinVersion by System.getProperties()
    val kraalVersion by System.getProperties()

    kotlin("jvm") version "$kotlinVersion"
    id("com.hpe.kraal") version "$kraalVersion"
}

Hope it helps you.