ExpediaGroup / graphql-kotlin

Libraries for running GraphQL in Kotlin
https://opensource.expediagroup.com/graphql-kotlin/
Apache License 2.0
1.74k stars 348 forks source link

Could not initialize class kotlinx.coroutines.BlockingEventLoop #747

Closed androa closed 4 years ago

androa commented 4 years ago

Library Version 3.0.0

Describe the bug

Execution failed for task ':graphqlIntrospectSchema'.
> Could not initialize class kotlinx.coroutines.BlockingEventLoop

To Reproduce Started a new Gradle project with gradle init --type kotlin-application --dsl kotlin and the following build.gradle.kts (as per the example in https://medium.com/expedia-group-tech/introducing-graphql-kotlin-client-b32dc3061a6f):

import com.expediagroup.graphql.plugin.gradle.graphql

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.3.71"
    application
    id("com.expediagroup.graphql") version "3.0.0"
}

repositories {
    jcenter()
}

dependencies {
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

    implementation("com.expediagroup:graphql-kotlin-client:3.0.0")

    testImplementation("org.jetbrains.kotlin:kotlin-test")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}

application {
    mainClassName = "foo.AppKt"
}

graphql {
    client {
        endpoint = "http://localhost:8080/graphql"
        packageName = "com.example.generated"
    }
}

Expected behavior The GraphQL SDL to be downloaded

dariuszkuc commented 4 years ago

This is weird.... I just tried following the same steps:

  1. create new project using gradle init --type kotlin-application --dsl kotlin
  2. modify the build script with plugin + extension configuration (as per your example)
  3. add simple HelloWorld query (https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/client/gradle-client/src/main/resources/ExampleQuery.graphql)
  4. start up example server (https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples/client/server)
  5. run gradle clean build -> it failed but it complained about trying to inline code built with Java 1.8 (i.e. graphql kotlin client lib) and my test project using 1.6
  6. updated build script with

    tasks {
    compileKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs = listOf("-Xjsr305=strict")
    
        }
    }
    }
  7. re-run the gradle clean build and it generated successfully...

Whats your environment? e.g. I'm building using Gradle 6.3 (using Kotlin 1.3.70 and Java 11.0.5).

androa commented 4 years ago

It seemed to help upgrading Gradle. Went from 6.2 to 6.5, now it works.

./gradlew --version

------------------------------------------------------------
Gradle 6.2
------------------------------------------------------------

Build time:   2020-02-17 08:32:01 UTC
Revision:     61d3320259a1a0d31519bf208eb13741679a742f

Kotlin:       1.3.61
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          13.0.2 (Oracle Corporation 13.0.2+8)
OS:           Mac OS X 10.15.5 x86_64

After upgrading to:

------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          13.0.2 (Oracle Corporation 13.0.2+8)
OS:           Mac OS X 10.15.5 x86_64

It seems like the plugin will be executed with the Kotlin version Gradle brings, not what is defined in the build.gradle.kts. TIL.