Kotlin, gradle, idea - unresolved reference while using javaClass


#1

Hello, I’m stepping first steps with kotlin and today I have faced the issue as follows:

I’m getting this:

While trying to set up logger. It can’t be imported. Even if I manually type the import declaration it can’t see this.

My gradle config is:

group 'org.dreando'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.1.2-2'
    ext.spring_boot_version = '1.5.3.RELEASE'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
    }
}

apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'org.springframework.boot'
apply plugin: 'application'

jar {
    baseName = 'bt-server'
    version = '0.0.1'
}

springBoot {
    mainClass = 'org.dreando.ServerRunner.kt'
}

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib"
    compile 'org.springframework.boot:spring-boot-starter'
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile "org.springframework.boot:spring-boot-starter-data-mongodb"
    testCompile "org.springframework.boot:spring-boot-starter-test"
    testCompile 'junit:junit'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.9'
}

Do you have any idea what could I messed up here?

Btw - the idea plugin version matches the one from gradle.

Thanks in advance for any help.


#2

The javaClass function is an old way to access the Java class of an object which only existed in Kotlin versions before 1.0. You need to use TestService::class instead. See the documentation for more information.


#3

In fact even

TestService::class.java

Thank you :slight_smile: