Friso
Friso

Reputation: 1110

Can't get Kotlin classes in Java maven project to work (Eclipse)

I've got a maven (DropWizard) java project. I'd really like to add some Kotlin classes, but seem unable to do so. In my real project I've added the maven configuration like https://kotlinlang.org/docs/reference/using-maven.html#compiling-kotlin-and-java-sources, but my Kotlin classes aren't seen by the 'normal' java code. Neither by maven nor by Eclipse.

So I tried the mixed-source example https://github.com/JetBrains/kotlin-examples/tree/master/maven/mixed-code-hello-world. That worked in Maven, but still not in Eclipse.

What am I missing here?

This is my workspace

Upvotes: 4

Views: 3285

Answers (1)

Mikhail Zarechenskii
Mikhail Zarechenskii

Reputation: 311

It seems that there are several issues.

Eclipse doesn't recognize src/main/kotlin as source directory. To fix it, please add the directory to the classpath manually: properties for mixed-code-hello-world -> Java Build Path -> Source tab -> Add Folder...

Then, try to Remove and Add Kotlin Nature to reindex Kotlin files in the project. To do this, press right-click on the project -> Configure Kotlin -> Remove Kotlin Nature.Kotlin Configuration

I've created tickets for these problems:

  1. Eclipse does not recognize kotlin source directory
  2. Kotlin plugin does not reindex files after adding source directory

Upvotes: 4

Related Questions