I'm trying to compile maven project which has Kotlin classes referencing Java classes. Here's a part of my parent POM:
...
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin-version}</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.plugin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<scanForAnnotations>false</scanForAnnotations>
</configuration>
</plugin>
And related parts of the child POM:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
</dependency>
...
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<configuration>
<sourceDirs>
<source>${project.basedir}/src/main/kotlin</source>
</sourceDirs>
</configuration>
</plugin>
And the Kotlin class:
Stateless
open class DummyServiceImpl : DummyService {
PersistenceContext(unitName = Consts.UNIT_NAME)
private val em: EntityManager? = null
override fun get(id: Long?): Dummy {
return em!!.find<Dummy>(javaClass<Dummy>(), id)
}
override fun sayHi(): String {
return "Dummy service says \"Hi!\"."
}
}
DummyService
and Consts
classes are Java classes residing in the same module as DummyServiceImpl
.
So when I compile the module containing DummyServiceImpl
with Maven it goes like this:
[error] C:\somepath\service\DummyServiceImpl.kt: (14, 31) Unresolved reference: DummyService
[error] C:\somepath\service\DummyServiceImpl.kt: (16, 35) Unresolved reference: Consts
If I switch Kotlin plugin execution phase
to compile
then it predictably fails if there're references from Java to Kotlin classes:
[ERROR] /C:/somepath/service/impl/DummyServiceClientImpl.java:[5,27] cannot find symbol
[ERROR] symbol: class DummyServiceImpl
So, what's to be done about this? Note that building with IDEA's make
goes perfectly fine.