Kotlin unable to find POJOs


#1

Hi,

I started using Kotlin today and came across a strange error. When I compile my Maven project on the command line (mvn clean install -DskipTests=true), it fails:

[ERROR] /Users/lerk/workspace/lolpix2.0/src/main/kotlin/org/lolpix/api/UserRepo.kt: (3, 23) Unresolved reference: entities [ERROR] /Users/lerk/workspace/lolpix2.0/src/main/kotlin/org/lolpix/api/UserRepo.kt: (11, 36) Unresolved reference: User [ERROR] /Users/lerk/workspace/lolpix2.0/src/main/kotlin/org/lolpix/api/UserRepo.kt: (12, 42) Unresolved reference: User [ERROR] /Users/lerk/workspace/lolpix2.0/src/main/kotlin/org/lolpix/api/UserRepo.kt: (13, 30) Unresolved reference: User

The first unresolved reference is the package name of the following ones. (org.lolpix.api.entities.User)

When I compile my project in IntelliJ it just works.

Any help is appreciated.


#2

Are the files in the ‘entities’ package located under the same directory as UserRepo.kt?


#3

No. :sweat:

The User repo is in /src/main/kotlin/org/lolpix/api/UserRepo.kt
The POJOs are in /src/main/java/org/lolpix/api/entities/*.java

This is the way IntelliJ set up the project.


#4

Did you follow these instructions for setting up mixed Java/Kotlin compilation? https://kotlinlang.org/docs/reference/using-maven.html#compiling-kotlin-and-java-sources


#5

I think so. I originally set up the project using the Spring Initializr (in IntelliJ) and then added Java classes to it.

Here’s my config:

<plugin> <artifactId>kotlin-maven-plugin</artifactId> <groupId>org.jetbrains.kotlin</groupId> <version>${kotlin.version}</version> <executions> <execution> <id>compile</id> <phase>process-sources</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>test-compile</phase> <goals> <goal>test-compile</goal> </goals> </execution> </executions> </plugin>