Attempt to use Kotlin class in Java results in "cannot find symbol"

I have some Kotlin code that I’m trying to utilize from Java. I’m using gradle and have a few Kotlin classes in my code base but this is the first time I’ve attempted to call Kotlin from Java.

IntelliJ is happy with the code but when I try to build the project with gradle it fails with “cannot find symbol”. I see the class has been built so I’m puzzled as to why it’s not found.

1 Like

How exactly is your Gradle build set up? You can find an example of setting up a mixed Kotlin/Java project with Gradle here.

Thanks for the link. I actually had looked at that prior to posting and found it helpful as a point of reference. I am able to build that project without issues.

My build.gradle file has a great many more dependencies but I think the only differences that stood out were the following.

I don’t have either of these statements:

sourceSets {
  deploy
}
...
test.testClassesDir = project.tasks.compileTestKotlin.destinationDir

On the last one, of course, I mean I don’t have anything equivalent in my build (ie, test.testClassesDir). I’m using the latest version of Kotlin as well.

I guess the best approach here is for me to create a stripped down version of my project to see if I can recreate the issue there.

After some more digging, I think the issue is with the annotation processing or code generation that occurs as part of the build. We are using querydsl with Spring support for MongoDB. The build fails when it hits the MongoAnnotationProcessor part of the build. I tried following the instructions I could find about this using kapt but it didn’t seem to help.

1 Like

I’ve created an example application that duplicates this issue:

It seems that the MongoAnnotationProcessor is triggering the issue but that for that to occur there needs to be a reference to a Kotlin class in a Spring class with annotations (I’m not sure if the annotations is key but I suspect so).

1 Like

Same issue. Show stopper.

1 Like

I am having the a similar issue but i have no MongoAnnotationProcessor