4

I have created Spring Boot project with

  • SDK 11. Java Version 11.0.3
  • Kotlin as language
  • Gradle

I'm following this Tutorial: https://scotch.io/@grahamcox82/how-to-build-a-simple-rest-api-with-kotlin-and-spring-boot

I'm trying to

import java.time.Instant

in my Kotlin data class

And have an error

Unresolved reference: java

build.gradle.kts file:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.1.6.RELEASE"
    id("io.spring.dependency-management") version "1.0.7.RELEASE"
    kotlin("jvm") version "1.2.71"
    kotlin("plugin.spring") version "1.2.71"
}

group = "com.smight"
version = "0.0.1"
java.sourceCompatibility = JavaVersion.VERSION_1_8

val developmentOnly by configurations.creating
configurations {
    runtimeClasspath {
        extendsFrom(developmentOnly)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("io.projectreactor:reactor-test")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

Maybe I should install java library? How can I check this? Can anyone help please?

1
  • you should edit your question to add the code you are trying to execute so that we can understand better what you are talking about. Check this link Commented Aug 7, 2019 at 7:36

3 Answers 3

3

According to some research, this error can appear in this conditions :

  • You created a Kotlin2Js project instead of Kotlin JVM (source), try to recreate your project by selecting the right project type

or

  • You are using a Kotlin version that does not support JDK 11 (source), install JDK 8 instead and reconfigure your JAVA_HOME environment variable

It may as well be an error in your build.gradle file, copy/paste it in your question if the solutions above doesn't work

Sign up to request clarification or add additional context in comments.

1 Comment

I've created with Spring Initializr a new Spring Boot Project with Project SDK 11 (java version 11.0.3). And then I've chosen Java Version 11. I have the latest Kotlin Version. Thank you for the antwort
1

To get a more specific error you should first clean the autogenerated files

$ ./gradlew clean

In a modularized Spring project using Kotlin DSL the unresolved reference error could occur because the submodules are bootable.

build.gradle.kts (Project)

...

subprojects {

    ...

    tasks.getByName<BootJar>("bootJar") {
        enabled = false
    }

    tasks.getByName<Jar>("jar") {
        enabled = true
    }

}

GL

Comments

-1

The problem was that JDK was not correct found from IntelliJ

I solved the problem so:

  1. File -> Project Structure -> SDKs -> "+"
  2. Find the path to your SDK where it is installed
  3. New Project
  4. Copy/Paste
  5. Rebuild

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.