0
votes

I'm trying to import kotlin coroutines in my spring project.

I have the following lines in my build.gradle file:

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

But anyways when I import coroutines-common using implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1' I get the error: Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option

If I remove implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1' the project builds fine.

How can I import kotlin coroutines?

P.S. I tried

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions { 
        apiVersion = "1.3"
        languageVersion = "1.3"
        jvmTarget = "1.8"
    }
}

Full build.gradle file:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
        classpath("org.jetbrains.kotlin:kotlin-noarg:1.3.20")
        classpath("org.jetbrains.kotlin:kotlin-allopen:1.3.20")
    }
}

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'org.jetbrains.kotlin.jvm' version '1.3.20'
    id 'org.jetbrains.kotlin.plugin.spring' version '1.3.20'
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'kotlin-jpa'

allOpen {
    annotation("javax.persistence.Entity")
    annotation("javax.persistence.MappedSuperclass")
    annotation("javax.persistence.Embeddable")
}

group = 'com.liberaid'
version = '0.0.1'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
    maven { url "https://dl.bintray.com/rookies/maven"  }
}

dependencies {
    def withoutX = {
        exclude group: 'org.slf4j', module: 'slf4j-log4j12'
        exclude group: 'org.slf4j', module: 'slf4j-jdk14'
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }

    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
    implementation 'commons-net:commons-net:3.6'
    implementation 'net.lingala.zip4j:zip4j:1.3.2'
    implementation 'org.apache.pdfbox:pdfbox:2.0.1'

    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'mysql:mysql-connector-java:+'

    /* Json parsers */
    implementation 'org.json:json:+'
    implementation 'com.google.code.gson:gson:+'

    /* HTML parser */
    implementation 'org.jsoup:jsoup:1.11.3'

    /* GROBID - citation parser */
    implementation 'org.grobid:grobid-core:0.5.4', withoutX
    implementation 'org.grobid:grobid-trainer:0.5.4', withoutX

    /* Kotlin coroutines */
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1'

    runtimeOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

compileKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}

compileTestKotlin {
    kotlinOptions {
        freeCompilerArgs = ['-Xjsr305=strict']
        jvmTarget = '1.8'
    }
}
1
I think "implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1'" should be "implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1'" - Alexander Egger
Oh, really. This helps. Write it as standalone answer, Ill mark it as solution - whý

1 Answers

1
votes

The dependency org.jetbrains.kotlinx:kotlinx-coroutines-common:1.1.1 is wrong.

Use org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.1.1 instead.