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

Compilation of gradle Java 11 project failed #288

Closed
mdddj opened this issue Jan 15, 2023 · 8 comments
Closed

Compilation of gradle Java 11 project failed #288

mdddj opened this issue Jan 15, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@mdddj
Copy link

mdddj commented Jan 15, 2023

Describe the bug

Compilation failed in gradle configuration project

Reproduction and additional details

Could not determine the dependencies of task ':prepareSandbox'.
> Could not resolve all files for configuration ':runtimeClasspath'.
   > Could not resolve org.hildan.krossbow:krossbow-websocket-okhttp:4.5.0.
     Required by:
         project :
      > No matching variant of org.hildan.krossbow:krossbow-websocket-okhttp:4.5.0 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'apiElements' capability org.hildan.krossbow:krossbow-websocket-okhttp:4.5.0 declares a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares an API of a component compatible with Java 17 and the consumer needed a runtime of a component compatible with Java 11
          - Variant 'runtimeElements' capability org.hildan.krossbow:krossbow-websocket-okhttp:4.5.0 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
          - Variant 'sourcesElements' capability org.hildan.krossbow:krossbow-websocket-okhttp:4.5.0 declares a runtime of a component, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                  - Doesn't say anything about its target Java version (required compatibility with Java 11)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

Context

  • Krossbow version: 4.5.0
  • Krossbow artifacts used: krossbow-stomp-core,krossbow-websocket-okhttp
  • Kotlin version: 1.7.20
  • Kotlin target(s):

my config file

plugins {
    id("java")
    id("org.jetbrains.kotlin.jvm") version "1.7.20"
    id("org.jetbrains.intellij") version "1.12.0"
}

repositories {
    mavenCentral()
    google()
    maven { url = uri("https://maven.pkg.jetbrains.space/public/p/compose/dev") }
    maven {
        url = uri("https://plugins.gradle.org/m2/")
    }
}
java{
    sourceCompatibility = JavaVersion.VERSION_11
}



dependencies {
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
    implementation ("com.squareup.retrofit2:converter-scalars:2.9.0")
    implementation("com.github.ben-manes.caffeine:caffeine:3.1.2")
    implementation("cn.hutool:hutool-all:5.8.11")
    implementation("org.smartboot.socket:aio-core:1.6.1")
    implementation("com.alibaba.fastjson2:fastjson2:2.0.22")
    implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.22")
    implementation("org.apache.commons:commons-lang3:3.12.0")
    implementation("com.google.code.gson:gson:2.10.1")
    implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0")
    implementation("org.hildan.krossbow:krossbow-stomp-core:4.5.0")
    implementation("org.hildan.krossbow:krossbow-websocket-okhttp:4.5.0")
    implementation("com.google.guava:guava:31.1-jre")
}


var javaVersion = "11"

tasks {
    withType<JavaCompile> {
        sourceCompatibility = javaVersion
        targetCompatibility = javaVersion
    }
    withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        kotlinOptions.jvmTarget = javaVersion
    }

    withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
        kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
    }

    listProductsReleases {
    }


    runIde {
        autoReloadPlugins.set(true)
    }


    buildSearchableOptions {
        enabled = false
    }

    compileKotlin {
        kotlinOptions.jvmTarget = javaVersion
    }

    compileTestKotlin {
        kotlinOptions.jvmTarget = javaVersion
    }
}
@mdddj mdddj added the bug Something isn't working label Jan 15, 2023
@joffrey-bion
Copy link
Owner

Thanks for the report, I made a mistake in the CI config and I'm now publishing with byte code level 17. This was unintentional.

I'll release a patch for java 11 compatibility

joffrey-bion added a commit that referenced this issue Jan 16, 2023
@joffrey-bion joffrey-bion reopened this Jan 16, 2023
@joffrey-bion
Copy link
Owner

joffrey-bion commented Jan 16, 2023

It turns out there are some issues with the new macos runners that are only fixed with Kotlin 1.8. I will first migrate to Kotlin 1.8 and then will be able to move forward with the JDK 11 CI setup, sorry.

The Gradle error for reference:

* What went wrong:
Execution failed for task ':krossbow-websocket-builtin:allTests'.
> Failed to execute all tests:
  :krossbow-websocket-builtin:watchosX64Test: java.lang.IllegalStateException: command '/usr/bin/xcrun' exited with errors (exit code: 148)

It happens on GitHub Actions macos-12 runner. Should be solved in Kotlin 1.8, see https://youtrack.jetbrains.com/issue/KT-54814

@mdddj
Copy link
Author

mdddj commented Jan 16, 2023

Ok, thank you for your reply. I will upgrade kotlin to 1.8

@joffrey-bion
Copy link
Owner

Sorry if I was unclear. I meant the issues on GA runner prevent me from releasing a patch for krossbow. So I will upgrade Krossbow to Kotlin 1.8 in order to fix the build and be able to release again. I didn't mean you should upgrade on your side to fix the java 11 issue.

That being said, the next version of krossbow with jdk11 support will indeed be using kotlin 1.8, so you might need to upgrade on your side when upgrading krossbow.

@mdddj
Copy link
Author

mdddj commented Jan 16, 2023

Thank you for your reminder. I understand. Now I temporarily remove this dependency to solve the problem, and add it again after the dependency version is upgraded

@joffrey-bion
Copy link
Owner

joffrey-bion commented Jan 18, 2023

@mdddj Actually, I double checked, and despite the CI using JDK 17 to compile the classes, the default Kotlin target JVM bytecode was still Java 8. I just checked the class files from org.hildan.krossbow:krossbow-websocket-okhttp:4.5.0 and they are indeed at class version 52.0:

OkHttpWebSocketClient.class: compiled Java class data, version 52.0 (Java 1.8)
KrossbowToOkHttpListenerAdapter.class: compiled Java class data, version 52.0 (Java 1.8)

I released Krossbow version 5.0.0 which compiled all artifacts on CI using JDK 11, but the result is the same: java 8 compatible bytecode by default.

I think your issue might be that you're using an old Gradle version that doesn't recognize the metadata properly.

Could you please check the following:

  1. try with Krossbow 5.0.0 and your current Gradle version
  2. try with Krossbow 4.5.0 and Gradle 7.6
  3. try with Krossbow 5.0.0 and Gradle 7.6

Do you still have the error in either of those? I would assume you have the same error in 1) but the error is gone in 2) and 3). Is this correct?

@mdddj
Copy link
Author

mdddj commented Jan 19, 2023

After I upgrade, there are no problems with the above three points

@joffrey-bion
Copy link
Owner

After you upgrade what exactly? Some of the points are about not upgrading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants