Getting an error “cannot find symbol” while trying to compile a Kotlin-Java mixed project with Gradle

I’m working on a Java-Kotlin mixed project (not using android). When I try to compile project, I get “cannot find symbol” error wherever I refer to Kotlin class from Java class. I followed instructions in the Kotlin documention and also tried solutions in other questions, but it doesn’t work.

I’ve put all Java files in src/main/java, and all Kotlin files in src/main/kotlin.

Below is build.gradle I’m using.

buildscript {
    repositories {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath "com.github.jengelman.gradle.plugins:shadow:$shadowVersion"

plugins {
    id 'java'

if (!project.getPlugins().hasPlugin('org.jetbrains.kotlin.jvm')) {
    apply plugin: 'org.jetbrains.kotlin.jvm'

if (!project.getPlugins().hasPlugin('com.github.johnrengelman.shadow')) {
    apply plugin: 'com.github.johnrengelman.shadow'

def properties = new Properties()
new File(project.projectDir, '../../').withInputStream() { properties.load(it) }

group = properties.getProperty('group')
version = properties.getProperty('version')
sourceCompatibility = properties.getProperty('sourceCompatibility')

compileJava.options.encoding = 'UTF-8'

sourceSets {
    main.kotlin.srcDirs += 'src/main/kotlin' += 'src/main/java'

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        freeCompilerArgs = ['-Xjvm-default=compatibility']
        jvmTarget = '1.8'

jar {
    finalizedBy shadowJar

repositories {

dependencies {
    compile project(':Compatibility')
    compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:' + properties.getProperty('kotlinVersion')
    compile '' + properties.getProperty('guavaVersion')
    compile '' + properties.getProperty('gsonVersion')
    compileOnly 'org.jetbrains:annotations:' + properties.getProperty('annotationsVersion')
} :

How can I solve this problem?

1 Like

Failed to reproduce with a dummy project following your build config. Can you please share some sample project to reproduce?

I’m concerned too, and I’m able to reproduce it on Kotlin 1.4.x (worked fine on 1.3.x) : here’s a POC.

The problem is triggered when calling a Kotlin method returning an inline classes from Java:

inline class Baz(val value: Double)

interface Foo {
   fun get(value: Int): Baz
class Bar {

    private final Foo foo;

    private Bar(@NonNull Foo foo) { = foo;

    private double baz(int value) {
        return foo.get(value); // error: cannot find symbol
} (56.8 KB)

1 Like